0

I'm trying to use jQuery to fire an event on scroll on a particular class of elements, like so:

$('body').on('scroll', '.overflow', function() { do stuff; });

However, do stuff never happens. I've done a little experimentation, and it looks as though the scroll event can't be delegated using .on. (see http://jsbin.com/aJeDiru/2 for a test case).

Is there a way that I can get it to delegate? Or is there a Very Good Reason™ why it should never be set up to delegate in this fashion?

2
  • Well "scroll" is a weird event for bubbling, because it doesn't necessarily make sense for a parent element to get it if the child element scrolls independently. Commented Sep 4, 2013 at 21:18
  • stackoverflow.com/questions/10625104/… This should help (not the accepted answer though, the others). Commented Sep 4, 2013 at 21:29

2 Answers 2

3

According to W3, the scroll event doesn't bubble.

Since event delegation relies on the event bubbling to the element you've attached the handler to, you won't be able to use delegation.

Sign up to request clarification or add additional context in comments.

Comments

2

Use "mousewheel" instead,
make sure #contents is on the main html file.

    $("#contents").on('mousewheel',function(e) {
    if(e.originalEvent.wheelDelta /120 > 0) {
         //do something to the loaded elements
     } else {
        //do something to the loaded elements
     }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.