Scroll To Top component using id

 <ul> @for(data of aboutMenuList; track data){ <li (click)="handleMenuActive(data?.id)"><a [class]="isSelected==data?.id ? 'active': ''">{{data?.title}}</a></li> } </ul> <div class="about-main-child-right"> <app-about-us id="0"></app-about-us> <!-- END! app-about-us --> <app-about-our-values id="1"></app-about-our-values> <!-- END! about-our-values --> <app-about-our-partners id="2"></app-about-our-partners> <!-- END! about-our-partners --> <app-about-our-team id="3"></app-about-our-team> <!-- END! about-our-team --> <app-you-can-trust-us id="4"></app-you-can-trust-us> <!-- END! you-can-trust-us --> <app-about-our-story id="5"></app-about-our-story> <!-- END! about-our-story --> <app-about-where-we-operate id="6"></app-about-where-we-operate> <!-- END! about-where-we-operate --> </div>
Enter fullscreen mode Exit fullscreen mode
 aboutMenuList: any[] = [ { id: 0, title: 'About Us' }, { id: 1, title: 'Our Values' }, { id: 2, title: 'Our Partners' }, { id: 3, title: 'Our Team' }, { id: 4, title: 'Trust' }, { id: 5, title: 'Our Story' }, { id: 6, title: 'Where We Work' }, ]; handleMenuActive(id: any) { let element = document.getElementById(id); if (element) { // element.scrollIntoView({ behavior: 'smooth', block: 'start' }); const rect = element.getBoundingClientRect(); const offset = 100; const scrollTop = window.pageYOffset + rect.top - offset; window.scrollTo({ top: scrollTop, behavior: 'smooth' }); } }
Enter fullscreen mode Exit fullscreen mode

Alternative

 <ul> @for(data of aboutMenuList; track data){ <li (click)="handleMenuActive(data?.id)"><a [class]="isSelected==data?.id ? 'active': ''">{{data?.title}}</a></li> } </ul> <div class="about-main-child-right"> <app-about-us id="0"></app-about-us> <!-- END! app-about-us --> <app-about-our-values id="1"></app-about-our-values> <!-- END! about-our-values --> <app-about-our-partners id="2"></app-about-our-partners> <!-- END! about-our-partners --> <app-about-our-team id="3"></app-about-our-team> <!-- END! about-our-team --> <app-you-can-trust-us id="4"></app-you-can-trust-us> <!-- END! you-can-trust-us --> <app-about-our-story id="5"></app-about-our-story> <!-- END! about-our-story --> <app-about-where-we-operate id="6"></app-about-where-we-operate> <!-- END! about-where-we-operate --> </div>
Enter fullscreen mode Exit fullscreen mode
 aboutMenuList: any[] = [ { id: 0, title: 'About Us' }, { id: 1, title: 'Our Values' }, { id: 2, title: 'Our Partners' }, { id: 3, title: 'Our Team' }, { id: 4, title: 'Trust' }, { id: 5, title: 'Our Story' }, { id: 6, title: 'Where We Work' }, ]; handleMenuActive(id: any) { let element = document.getElementById(id); if (element) { element.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }
Enter fullscreen mode Exit fullscreen mode

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Building a green smart home. Free 2025 jamb questions and answers cbt answers jamb / jamb 2025 answers cbt answers jamb. Additional strategies for integrating active listening into your career growth plan.