1

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.

user2304483
  • 1,462
  • 6
  • 28
  • 50

2 Answers2

1

Have you looked into ngx-page-scroll?

https://www.npmjs.com/package/ngx-page-scroll

this will allow you to only have to add one attribute and a target location to a link element, and reference a different element on the page.

<a pageScroll href="#monthlyDeals">Monthly Promos</a>
<!-- Content --->
<div id="monthlyDeals">(Content Goes Here)</div>

Their documentation is straightforward to follow and worked for an application I needed it for.

Willie
  • 281
  • 3
  • 21
-3

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

user2304483
  • 1,462
  • 6
  • 28
  • 50