2010-03-15 53 views
1

我使用滾動SWF文件..反正是有禁用所有瀏覽器的鼠標滾輪滾動..我得到它的IE和FF,但Webkit的工作不工作:禁用swf文件上的滾輪滾動?

$(document).ready(function() { 
$("#ebook").hover(
    function() { 
    document.onmousewheel = function(){ 
     return false 
    }; 
    console.log('On'); 
    }, 
    function() { 
    console.log('Out'); 
    document.onmousewheel = function() { 
     return true; 
    } 
    } 
); 

});

回答

1

在Web和JQuery的一些腳本的幫助下,我爲這個問題組裝了以下Javascript解決方案,並且它在所有瀏覽器上都能正常工作。
基於:http://adomas.org/javascript-mouse-wheel/
僅當鼠標進入容器div並重新啓用鼠標onMouseLeave時禁用。

jQuery(function(){ 
    $("#myFlashContainer").mouseenter(
    function() { 
     if (window.addEventListener) 
     { 
     window.removeEventListener('DOMMouseScroll', wheelOn, false); 
     window.addEventListener('DOMMouseScroll', wheelOff, false); 
     } 
     /** IE/Opera. **/ 
     window.onmousewheel = document.onmousewheel = wheelOff; 
    } 
); 

    $("#myFlashContainer").mouseleave(
    function() { 
     if (window.addEventListener) 
     { 
     window.removeEventListener('DOMMouseScroll', wheelOff, false); 
     window.addEventListener('DOMMouseScroll', wheelOn, false); 
     } 
     /** IE/Opera. **/ 
     window.onmousewheel = document.onmousewheel = wheelOn; 
    } 
); 

    function wheelOff(event) 
    { 
    var delta = 0; 
    if (!event) /* For IE. */ 
     event = window.event; 
    if (event.wheelDelta) { /* IE/Opera. */ 
     delta = event.wheelDelta/120; 
    } else if (event.detail) { /** Mozilla case. */ 
     /** In Mozilla, sign of delta is different than in IE. 
     * Also, delta is multiple of 3. 
     */ 
     // delta = -event.detail/3; 
    } 

    if (event.preventDefault) 
     event.preventDefault(); 
    event.returnValue = false; 
    } 

    function wheelOn(event) 
    { 
    var delta = 0; 
    if (!event) /* For IE. */ 
     event = window.event; 
    if (event.wheelDelta) { /* IE/Opera. */ 
     delta = event.wheelDelta/120; 
    } else if (event.detail) { /** Mozilla case. */ 
     // delta = -event.detail/3; 
    } 
    if (event.preventDefault) 
    { 
     //event.preventDefault(); 
     event.returnValue = true; 
    } 
    return true; 
    } 

}); 
+0

這似乎在firefox/webkit中工作..但不是IE 8 ...也沒有將焦點設置爲.swf – Chris 2010-07-22 07:56:57