在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.
  1. (function()
  2. {
  3. function addEventListener(event, elem, func)
  4. {
  5. if (elem.addEventListener)
  6. {
  7. return elem.addEventListener(event, func, false);
  8. }
  9. else if (elem.attachEvent)
  10. {
  11. return elem.attachEvent("on" + event, func);
  12. }
  13. }
  14.  
  15. function disableMouseWheel (event)
  16. {
  17. if(event.target.nodeName.toLowerCase().match(/embed|object/))
  18. {
  19. event.preventDefault();
  20. event.stopImmediatePropagation();
  21. return false;
  22. }
  23. }
  24.  
  25. var events = ['DOMMouseScroll', 'mousewheel'];
  26. for(var i = 0; i < events.length; i++)
  27. {
  28. addEventListener(events[i], document.body, disableMouseWheel);
  29. }
  30. })()

以上是关于在Flash元素中使用鼠标滚轮时禁用文档滚动的主要内容,如果未能解决你的问题,请参考以下文章

Actionscript 3,flexSDK,当它超过flash阶段时阻止鼠标滚轮滚动

html 禁用鼠标滚轮对网页滚动条的控制怎么实现?

JS怎么禁止鼠标滚轮的单击 IE下! 注意是滚轮去单击 而不是滚动!

带有硒网络驱动程序的鼠标滚轮,在没有滚动条的元素上?

在信息窗口中使用 Google Maps v3 禁用鼠标滚轮缩放

SWING禁用或隐藏滚动条,但启用滚轮?