I need to get scroll events from a div with overflow: scroll in my Angular 2 app.
It seems onscroll event do not works on Angular 2.
How could I achieve that?
To handle the onScroll event in React: Set the onScroll prop on an element or add an event listener on the window object. Provide an event handler function. Access relevant properties on the event or window objects.
To get or set the scroll position of an element, you follow these steps: First, select the element using the selecting methods such as querySelector() . Second, access the scroll position of the element via the scrollLeft and scrollTop properties.
The UIEvent type is used for onScroll events in React. You can access properties on the element, the event is attached to on the currentTarget property.
// @HostListener('scroll', ['$event']) // for scroll events of the current element @HostListener('window:scroll', ['$event']) // for window scroll events onScroll(event) { ... }
or
<div (scroll)="onScroll($event)"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With