此功能只能运行一次,该功能只能在Chrome和FF中运行。但是在IE中,您可以多次运行它。如何使它只能在IE中运行一次?
function topSect() {
var mouseY = 0;
var topValue = 10;
var executed = false;
window.addEventListener("mouseout", function(e) {
mouseY = e.clientY;
if (mouseY < topValue && !executed) {
//do something here
executed = true;
}
},
false);
};
答案 0 :(得分:1)
使用removeEventListener以确保仅一次触发了鼠标离开。
var mouseY = 0;
var topValue = 10;
var executed = false;
function mouseoutHandler(e){
window.removeEventListener("mouseout", mouseoutHandler, false);
mouseY = e.clientY;
exectued = true;
console.log(mouseY);
}
function topSect() {
window.addEventListener("mouseout", mouseoutHandler, false);
};
topSect();