1

EDIT:

Perhaps I am approaching this wrong - does anyone know any way of stopping the page from scrolling with the mouse wheel? Can this even be disabled?

--

I have a div container filled with smaller div's which animate when the mouse wheel is scrolled. This is not a div with overflow:hidden, and it has no scrolling areas - it is just a simple jquery animation (the animation works fine btw).

Unfortunately despite all my best efforts I cannot stop the entire page from scrolling whilst the mouse is inside the container div.

I am using Brandon Aaron's mousewheel plugin for jQuery (which is supposed to solve my problem, but unfortunately it isnt).

Here is my javascript:

$('#containerDiv').mousewheel(function(event,delta,deltaX,deltaY){
    /* all of this is supposed to stop the page from scrolling...  but it doesnt*/
    event.bubbles=false;
    event.cancelBubble=true;
    if(event.preventDefault) event.preventDefault();
    if(event.stopPropagation) event.stopPropagation();
    if(event.stopImmediatePropagation) event.stopImmediatePropagation();
    $(document).blur();
    $(this).focus();

    /*this function just animates the divs inside the container divs*/
    animateDivs(delta);
});

Ive been through these questions already:

Prevent scrolling of parent element?

stop mousewheel's continued effect

stop scrolling of webpage with jquery

and none of them seem to help.

Can anyone offer a better solution to this problem?

Community
  • 1
  • 1
Jimmery
  • 8,925
  • 23
  • 75
  • 142
  • $.mousewheel doesnt scroll elements. Its add scrolling elements by mousewheel. Your example it does. (MouseWhell scrolling is disabled. Scrollbar scrolling is enabled) http://jsfiddle.net/A8tjk/ – kubedan Jul 13 '12 at 08:56
  • This [answer](http://stackoverflow.com/a/4770179/1107651) to a similar question worked for me – Guilherme Torres Castro Jul 12 '12 at 20:24

1 Answers1

2

You can use galambalazs's solution as Guilherme Torres Castro answered. But it doesnt cancel scroll event. If you want cancel scroll event, you must add it. My fiddle solution inspirate by ntownsend's post.

Problem of this solution is "blicking"(hiding/showing) scrollbar. So I add scroll to actual scroll position on window.onScroll event and my FINAL SOLUTION is here

Final solution has problem when I try scrolling, but event beforeScroll doesnt exist https://stackoverflow.com/a/3352244/1102223

Community
  • 1
  • 1
kubedan
  • 606
  • 2
  • 7
  • 26