マウス入力時にトリガーされるコードブロックがあります。私はまた、マウスの動きが止まったことを検出するコードブロックを持っています。マウスが停止した後のトリガーコード
入力したオブジェクト内でマウスの移動が停止した場合にのみ、マウスセンターコードを実行してください。
// Add events to each dot
for (var i = 0; i < dots.length; i++) {
dots[i].addEventListener('mouseenter', function (event) {
var target = event.target;
// Add a class called moving when follow dot is in a transition
followDot.classList.add('moving');
targetsPosition[0] = target.style.left;
targetsPosition[1] = target.style.top;
// Detect if the dot is moving left or right
if (followDot.style.left < targetsPosition[0]) {
removeMovingClasses();
followDot.classList.add('moving-right');
} else if (followDot.style.left > targetsPosition[0]) {
removeMovingClasses();
followDot.classList.add('moving-left');
}
//
followDot.style.left = targetsPosition[0];
});
}
タイムアウトコード:
// Detect when the mouse has stopped
document.onmousemove = function(){
clearTimeout(timeout);
timeout = setTimeout(function() {
// console.log('mouse stopped');
}, 300);
}
が、これは動作しません... "最高" を定義するのに役立ちますか? – chazsolo
マウスが停止したときの検出が機能します。しかし、マウスが停止していない限り、最初のブロックのコードを実行したくありません。私はどのように2つを組み合わせるか分からない。 – MarioD
達成しようとしている効果は何ですか? –