Scroll to element on click in Angular 4

后端 未结 12 1008
逝去的感伤
逝去的感伤 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:16

    You could do it like this:

    
    
    Your target

    and then in your component:

    scroll(el: HTMLElement) {
        el.scrollIntoView();
    }
    

    Edit: I see comments stating that this no longer works due to the element being undefined. I created a StackBlitz example in Angular 7 and it still works. Can someone please provide an example where it does not work?

提交回复
热议问题