2015-09-06 105 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