2016-08-01 66 views
-4

造型/標頭列出引用文字代碼HTML高級的幫助»onmousewheel事件不能在Firefox

<script> 
function event_branding() { 
     document.getElementById("branding_fade").style.bottom = "0%"; 
     document.getElementById("branding_fade").style.opacity = "1"; 
     document.getElementById("branding_fade").style.transition = "all 2s"; 
     setTimeout(function() { $(".event_branding").css("visibility", "visible")},100); 
} 
</script> 
+0

這是調用函數 –

+0

功能event_branding(){ 的document.getElementById( 「branding_fade」)style.bottom = 「0%」。 document.getElementById(「branding_fade」)。style.opacity =「1」; document.getElementById(「branding_fade」)。style.transition =「all 2s」; setTimeout(function(){$(「。event_branding」)。css(「visibility」,「visible」)},100); } –

+0

[文檔](https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel) –

回答

0

這將工作。

window.addEventListener('DOMMouseScroll', mouseWheelEvent);  

這是一個jquery的例子。

http://codepen.io/damianocel/pen/vLerPM

現在,這是爲什麼不給大家或所有瀏覽器的工作,因爲這不是一個標準功能。

此外,MDN說:

在壁虎17(火狐17)或更高版本,你需要它必須爲每個本地事件被觸發輪事件調用preventDefault()方法。

在Gecko 16或更早版本中,您需要調用MozMousePixelScroll事件的preventDefault(),該事件必須針對每個本機事件觸發。

總而言之,瀏覽器支持非常糟糕,請勿將其用於生產站點。

+1

你能做的至少是格式正確。請解釋其原因,而不僅僅是郵政編碼 – Li357

+0

我使用此代碼來調用函數document.getElementById(「event_branding1」)。addEventListener('DOMMouseScroll',event_branding());但不適用於Firefox –

0

你的代碼不是很清楚。反正我會把我的例子在這裏希望它有助於

document.getElementById("myDIV").addEventListener("wheel", foo); 
function foo() { 
    console.log("Wheel scrolled") 
} 

嘗試一下在JS FIDDLE

我測試,它在Firefox和Chrome的工作以及

一個瀏覽器的兼容性更細緻的工作進行了說明HERE

1

試試這個

<div class="col-xs-7" style="padding-right:3px;"> 
    <img id="train_1_img" class="imageshow_temp" src="http://dummyimage.com/600x400/000/fff"/> 
</div> 

使用此腳本

var image = document.getElementById("train_1_img"); 
    if (image.addEventListener) { 
    // IE9, Chrome, Safari, Opera 
    image.addEventListener("mousewheel", MouseWheelEvent); 
    // Firefox 
    image.addEventListener("DOMMouseScroll", MouseWheelEvent); 
} 

function MouseWheelEvent(e) { 
console.log('event', e) 
// your statement here... 
} 

https://jsfiddle.net/fahadsaeed/f8ky3xkq/