Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get on scroll events?

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?

like image 550
Natanael Avatar asked Dec 23 '16 16:12

Natanael


People also ask

How do I get a scroll event in React?

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.

How do I get scroll position?

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.

What type is scroll event?

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.


1 Answers

// @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> 
like image 158
Günter Zöchbauer Avatar answered Oct 13 '22 05:10

Günter Zöchbauer