2015-09-06 103 views
0

我想每次向上滚动鼠标时触发鼠标滚轮事件。你们能帮我吗?因为它只发射一次。请参阅下面的代码。无限地触发鼠标滚轮事件

谢谢!

$('#foo').bind('mousewheel', function(e){ 
    if(e.originalEvent.wheelDelta /120 > 0) { 
     $("#room").trigger("click"); 
     foo = true; 
     mousewheel = true; 
    } 
    else{ 
     alert('down'); 
    } 

回答

0

鼠标滚轮事件是非标准,现在贬值,用香草wheel event而是

document.getElementById('foo').addEventListener('wheel', function (e) { 
    if (e.deltaY/120 > 0) { 
     $("#room").trigger("click"); 
     foo = true; 
     mousewheel = true; 
    } else { 
     alert('down'); 
    } 
}); 

the code in the compatibility section如果需要支持传统


实例证明它会多次点燃(使用控制台)

document.body.addEventListener('wheel', console.dir.bind(console)); 
+0

谢谢Paul!我知道它在控制台上工作,但事件本身不会无限发生。你能帮我再检查一次吗?再次,谢谢! – Cryptonym