Disable browser scrolling with the middle mouse scroll button
Asked Answered
Q

4

3

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?

Quadrille answered 31/3, 2010 at 15:2 Comment(0)
C
5

You can use:

document.body.style.overflow=allowScroll?"":"hidden";

Where allowScroll is a boolean.

Calia answered 31/3, 2010 at 17:47 Comment(1)
Very 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!Quadrille
H
12
<!-- 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/

Housebreaking answered 10/6, 2011 at 14:2 Comment(1)
I prefer this solution to the accepted one because it also allows to block scrolling via dragging the middle button.Stratocracy
C
5

You can use:

document.body.style.overflow=allowScroll?"":"hidden";

Where allowScroll is a boolean.

Calia answered 31/3, 2010 at 17:47 Comment(1)
Very 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!Quadrille
F
2
window.onscroll = function() {
    document.body.scrollTop = 0;
}
Fader answered 21/4, 2014 at 6:2 Comment(0)
U
0

SWFWheel: http://www.libspark.org/wiki/SWFWheel/en

Undercurrent answered 5/3, 2012 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.