0

How we can call a function when a user scrolls up or down in angular 6?

I'm willing to create something like fullpage.js in angular 6. First, I tried to solve this problem with angular animations but no success. Now, I'm making use of ngx-scroll-to for scrolling to current slide. So, consider I know how to write scroll_to_bottom_slide() and scroll_to_top_slide functions() in this example, But I don't know how to write the proper events.

example :

scrollDown(){
    scroll_to_bottom_slide();
}
scrollUp(){
    scroll_to_top_slide();
}

2 Answers2

1

You have to use @HostListener
source: https://brianflove.com/2016/10/10/angular-2-window-scroll-event-using-hostlistener

K. Ayoub
  • 406
  • 1
  • 5
  • 15
0

Add an event listener to the window...

window.addEventListener('scroll', ...some function...);

You could create a DI for the window just like here:

Angular2 - How to inject window into an angular2 service

tlm
  • 952
  • 10
  • 20