Search code examples
angularangular-animations

How to implement Scroll animation in Angular 8 with rxjs 6?


I have the current template:

<div id="top">
...
</div>

In the component I have the following method:

onTripSave() {
    let top = document.getElementById('top');
    if (top !== null) {
      top.scrollIntoView();
      top = null;
    }  
  }

This method scroll to top after finish save which works correctly. I need the scrollIntoView to not just scroll to top, I would make animation for that scroll. Please note that I'm using rxjs 6 so I need code with pipe I guess.


Solution

  • I prefer to use angular animation but for now I'm using jquery solution with the following:

    $("html, body").animate({ scrollTop: 0 }, "slow");
    

    I found the following solution but it's not valid rxjs 6 code: Angular 4 - Scroll Animation