Disable browser scrolling with the middle mouse scroll button

让人想犯罪 __ 提交于 2019-12-20 02:06:53

问题


I have a flash element on my page that you interact with by using the middle mouse scroll wheel. The page is long. So when scrolling with the mouse wheel it interacts with the Flash element AND scrolls the browser window.

Is there a way to disable browser scrolling while the Flash element is active?


回答1:


You can use:

document.body.style.overflow=allowScroll?"":"hidden";

Where allowScroll is a boolean.




回答2:


<!-- disables browser mouse scrolling -->
<script type="text/javascript">
if(window.addEventListener){
    window.addEventListener('DOMMouseScroll',wheel,false);
}

function wheel(event)
{
    event.preventDefault();
    event.returnValue=false;
}
window.onmousewheel=document.onmousewheel=wheel;
</script>

I have "extracted" this function from the Flash MouseWheelTrap which can be found here: http://code.google.com/p/mousewheeltrap/




回答3:


window.onscroll = function() {
    document.body.scrollTop = 0;
}



回答4:


SWFWheel: http://www.libspark.org/wiki/SWFWheel/en



来源:https://stackoverflow.com/questions/2554030/disable-browser-scrolling-with-the-middle-mouse-scroll-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!