Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does scroll event not bubble?

Today I've got kind of theoretical question. Why does scroll event not bubble? Is it connected with performance issues? I did some digging, but unfortunately didn't find any answers that would fulfill my curiosity.

Thanks for your replies :)

like image 677
kaapa Avatar asked Oct 29 '13 11:10

kaapa


People also ask

Does scroll event bubble?

The scroll event does not bubble up. Although the event does not bubble, browsers fire a scroll event on both document and window when the user scrolls the entire page.

How do I add a scroll to an event listener?

forEach(element => { window. addEventListener( "scroll", () => runOnScroll(element), { passive: true } ); }); Or alternatively, bind a single scroll listener, with evt => runOnScroll(evt) as handler and then figure out what to do with everything in elements inside the runOnScroll function instead.

Does scroll event work on mobile?

jQuery Mobile provides two scroll events: when scrolling starts and when scrolling stops.


1 Answers

It bubbles but not on elements. It bubbles at the document object up to document.defaultView (window of the document). This behavior happens to avoid performance issues (scroll events can fire at a high rate).

If you want to learn more about scrolling I would suggest reading the W3 documentation:

https://www.w3.org/TR/cssom-view/#scrolling

I hope it helps.

like image 139
Elvio Cavalcante Avatar answered Sep 27 '22 20:09

Elvio Cavalcante