Disable browser scrolling with the middle mouse sc

2019-02-25 10:54发布

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?

4条回答
戒情不戒烟
3楼-- · 2019-02-25 11:28
window.onscroll = function() {
    document.body.scrollTop = 0;
}
查看更多
ゆ 、 Hurt°
4楼-- · 2019-02-25 11:47

You can use:

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

Where allowScroll is a boolean.

查看更多
欢心
5楼-- · 2019-02-25 11:49
<!-- 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/

查看更多
登录 后发表回答