我正在监听mousemove
事件,根据鼠标位置为按钮添加一个不错的效果。然而,在移动设备上,如果我触摸按钮,事件也会被触发,使按钮跳到该位置。我更希望当通过触摸完成时,按钮忽略此事件,但我不知道如何实现这一点。
// The function is just a helper of mine (it ads addEventListener to the matched events
createEventListener('.hoverable', 'mousemove', function(e) {
// stripped out some calculations for simplicity reasons
const deltaX = 50;
const deltaY = 50;
const transformString = `translate3d(${deltaX}px, ${deltaY}px, 0)`;
this.style.mozTransform = transformString;
this.style.webkitTransform = transformString;
this.style.transform = transformString;
});