Disable browser scrolling with the middle mouse scroll button
Solution 1
You can use:
document.body.style.overflow=allowScroll?"":"hidden";
Where allowScroll is a boolean.
Solution 2
<!-- 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/
Solution 3
window.onscroll = function() {
document.body.scrollTop = 0;
}
Peter Craig
I'm a unicycling acrobat, artist, collector and recreational programmer. Dabbling in web, plugin and app development, framework tinkering, UX design, with a lean toward WordPress plugins and Google APIs (Google Maps, Analytics, AdWords). A little obsessed with statistics, marketing, behaviour and predictive data.
Updated on June 05, 2022Comments
-
Peter Craig almost 2 years
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?
-
Peter Craig about 14 yearsVery simple, I should have thought of it myself. Now I'm being lazy! So to complete the script, when disabling browser scrolling, simply swtich allowScroll = true/false. Thanks!
-
Kos over 12 yearsI prefer this solution to the accepted one because it also allows to block scrolling via dragging the middle button.