最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable browser scrolling with the middle mouse scroll button - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question asked Mar 31, 2010 at 15:02 Peter CraigPeter Craig 7,28919 gold badges62 silver badges74 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 12
<!-- 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/

You can use:

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

Where allowScroll is a boolean.

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

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

发布评论

评论列表(0)

  1. 暂无评论