/ Published in: JavaScript
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(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); } })()