我有一个在鼠标移动时触发的函数foo()
,因此只要鼠标移动,它就会被调用。
foo()
可以是任何数字。如果foo()
结果为100,则需要触发另一个函数3次。
我该怎么做?
document.addEventListener('mousemove', (e) => {
const whatINeed = foo(e)
// here we go: foo result is always a number
// if that number is 100 for 3 times
// fire another function
})
答案 0 :(得分:1)
document.addEventListener('mousemove', (() =>
let count=0;
return (e) => {
const whatINeed = foo(e)
if(whatINeed == 100) {
if(++count == 3) {
//fire another function
}
}
};
})());