Scroll to element on click in Angular 4

后端 未结 12 1032
逝去的感伤
逝去的感伤 2020-11-29 18:57

I want to be able to scroll to a target when a button is pressed. I was thinking something like this.

12条回答
  •  难免孤独
    2020-11-29 19:11

    There is actually a pure javascript way to accomplish this without using setTimeout or requestAnimationFrame or jQuery.

    In short, find the element in the scrollView that you want to scroll to, and use scrollIntoView.

    el.scrollIntoView({behavior:"smooth"});

    Here is a plunkr.

提交回复
热议问题