在Flash元素中使用鼠标滚轮时禁用文档滚动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Flash元素中使用鼠标滚轮时禁用文档滚动相关的知识,希望对你有一定的参考价值。
Often in Flash, the mouse is used to zoom or scroll, and by default the document tag will also pick this up, making the page scroll away - which is annoying when you just want to view the Flash element.This snippet intercepts mouse scroll over object or embed tags, and prevents the default behaviour.
The code is cross-browser, not dependent on a 3rd party library, and executes inside a self-executing function, so it won't pollute your global scope.
(function() { function addEventListener(event, elem, func) { if (elem.addEventListener) { return elem.addEventListener(event, func, false); } else if (elem.attachEvent) { return elem.attachEvent("on" + event, func); } } function disableMouseWheel (event) { if(event.target.nodeName.toLowerCase().match(/embed|object/)) { event.preventDefault(); event.stopImmediatePropagation(); return false; } } var events = ['DOMMouseScroll', 'mousewheel']; for(var i = 0; i < events.length; i++) { addEventListener(events[i], document.body, disableMouseWheel); } })()
以上是关于在Flash元素中使用鼠标滚轮时禁用文档滚动的主要内容,如果未能解决你的问题,请参考以下文章
Actionscript 3,flexSDK,当它超过flash阶段时阻止鼠标滚轮滚动
JS怎么禁止鼠标滚轮的单击 IE下! 注意是滚轮去单击 而不是滚动!