rajeev tejapuriya
rajeev tejapuriya

Reputation: 133

How to achieve smooth window scroll in angular2

For window scrolling, Currently I am using window.scrollTo() in angular2. Is any other way to achieve smooth scrolling in angular2.

Upvotes: 0

Views: 1384

Answers (1)

Roman Melnyk
Roman Melnyk

Reputation: 190

  1. Works only for Chrome, Firefox, Opera:

    html{
      scroll-behavior: smooth;
    }
    
  2. Works on all browsers: npm install scroll-behaviour

    component.ts

    smoothScroll(element) {
      (document.querySelector(element)).scrollIntoView({behavior: 'smooth', block: 'start'});
    }
    

    component.html

    <a (click)="smoothScroll('#about-sector')"> About</a>
    

Upvotes: 1

Related Questions