如何在悬停时禁用重新启动的功能

时间:2018-05-29 09:38:12

标签: javascript animation hover preventdefault

我试图让一个弹力球在用户上空盘旋。如果球再次交叉鼠标,我遇到了如何禁用重新启动功能的问题。它有时会导致一些冻结/错误。我不确定如何避免这种情况。你们有什么提示吗?

https://codepen.io/kombolo/pen/YvzPvm

谢谢!

{{1}}

1 个答案:

答案 0 :(得分:0)

Mouse hover is an extensive event. You are doing too much on hover.
what I would suggest is - set window.onmousemove = undefined in 
triggerAnimation function and then turn it on in the last. This helped a little.

function triggerAnimation() {
    window.onmousemove = void 0;

    xValues = [100, 0, 400];
    .....
    ....



    //loop: true
    });

    window.onmousemove = logMouseMove;

}