I have a #content
div and a button component.
When I click the button, I want to scroll to the top of the #content div.
HTML:
<div id="content">
Loren ipsum
</div>
<div (click)="toTop($event)">top</div>
topscroll.component.ts:
export class TopscrollComponent implements OnInit {
constructor() { }
ngOnInit() { }
toTop(event){
...
}
}
You can do that with plain javascript using .scrollIntoView()
:
toTop() {
document.getElementById("content").scrollIntoView();
}
Note: you don't need event
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With