使用鼠标中键滚动按钮禁用浏览器滚动

使用鼠标中键滚动按钮禁用浏览器滚动

问题描述:

我的页面上有一个Flash元素,您可以使用鼠标中键滚动鼠标来进行交互。该页面很长。所以当用鼠标滚轮滚动时,它与Flash元素交互并且滚动浏览器窗口。使用鼠标中键滚动按钮禁用浏览器滚动

有没有办法在Flash元素处于活动状态时禁用浏览器滚动?

您可以使用:

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

凡allowScroll是一个布尔值。

+0

很简单,我应该想到这一点我自己。现在我正在懒惰!因此,要完成脚本,禁用浏览器滚动时,只需启用allowScroll = true/false。谢谢! – 2010-04-01 05:09:28

<!-- 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> 

我有 “提取” 从Flash MouseWheelTrap此功能,可以在这里找到: http://code.google.com/p/mousewheeltrap/

+0

我更喜欢这个解决方案,因为它也允许通过拖动中间按钮来阻止滚动。 – Kos 2011-08-30 21:10:19

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