Revision: 56009
Updated Code
at March 5, 2012 21:35 by singalongwithdavehotmailcom
Updated Code
(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); } })()
Revision: 56008
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 5, 2012 21:32 by singalongwithdavehotmailcom
Initial Code
(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); } })()
Initial URL
Initial Description
Often in Flash, the mouse is used to zoom or scroll, and by default the document <body> 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.
Initial Title
Disable document scrolling when using mouse-wheel in Flash elements
Initial Tags
flash
Initial Language
JavaScript