Javascript 防止alert()方法触发两次
我正在编写一个脚本,当用户向上或向下滚动时,该脚本将在指定的div中显示不同的页面内容。现在我正在测试功能,当用户滚动时,只会弹出两个不同的警报。问题是Javascript 防止alert()方法触发两次,javascript,jquery,jquery-events,mousewheel,Javascript,Jquery,Jquery Events,Mousewheel,我正在编写一个脚本,当用户向上或向下滚动时,该脚本将在指定的div中显示不同的页面内容。现在我正在测试功能,当用户滚动时,只会弹出两个不同的警报。问题是alert()方法有时会触发两次,我不知道为什么 $(window).on('wheel', function(event){ if(event.originalEvent.deltaY < 0){ // mouse wheel up event.stopImmediatePropagation();
alert()
方法有时会触发两次,我不知道为什么
$(window).on('wheel', function(event){
if(event.originalEvent.deltaY < 0){
// mouse wheel up
event.stopImmediatePropagation();
alert("You scrolled up!");
}
else {
// mouse wheel down
event.stopImmediatePropagation();
alert("You scrolled down!");
}
});
$(窗口).on('wheel',函数(事件){
如果(event.originalEvent.deltaY<0){
//鼠标滚轮向上
事件。stopImmediatePropagation();
警报(“您已向上滚动!”);
}
否则{
//鼠标滚轮放下
事件。stopImmediatePropagation();
警报(“你向下滚动了!”);
}
});
使用该方法检查是否为事件调用了此方法