E
E
Extramezz2015-11-15 11:07:30
JavaScript
Extramezz, 2015-11-15 11:07:30

How to delegate scroll?

I want to hang a common onscroll handler for all elements on the page, how can I do this? Tried like this:

$(document).scroll(function(e){
   console.log(e.target);
});


Then so

$(document).on("scroll", "*", function(e){
   console.log(e.target);
});


Does not work. I understand that it can be done simply, but this is absolutely wrong and bad. How can onscroll be delegated? $("*").scroll(...);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2015-11-15
@Extramezz

You probably understand that pop-up events are delegated.
And when such misunderstandings happen with hanging events, do you always go to the sources to figure it out?

Bubbles No / Yes
When dispatched on the Document element, this event type MUST bubble to the Window object.

If you look at how the event stream is built in the browser , you can try the Capture Phase .
The result might be something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question