Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  185] [ 7]  / answers: 1 / hits: 22281  / 6 Years ago, fri, july 6, 2018, 12:00:00

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){
...
}
}

More From » angular

 Answers
7

You can do that with plain javascript using .scrollIntoView():



toTop() {
document.getElementById(content).scrollIntoView();
}





Note: you don't need event.


[#54038] Tuesday, July 3, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clarkulisesa

Total Points: 422
Total Questions: 93
Total Answers: 112

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
clarkulisesa questions
Mon, Feb 24, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;