javascript scroll to element
document.getElementById("divId").scrollIntoView();
javascript scroll to element
document.getElementById("divId").scrollIntoView();
on button click scroll to div angular
/?css or scss/
html {
scroll-behavior: smooth;
}
/?typescript/
//use ViewportScroller in angular
//in constructor
private _vps: ViewportScroller
//function
scrollFn(anchor: string): void{
this._vps.scrollToAnchor(anchor)
}
/?HTML/
<button (click)="scrollFn('about')">Scroll to div</button>
///About section
<div id="about">Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio, quasi nostrum labore sequi neque sed nihil consequuntur? Ea, dolorum minima,
cumque explicabo dicta est sit harum dolores, assumenda ex non.</div>
scrollto angular
//there are a few options you can go with, the basic one being css only
//css or scss
html {
scroll-behavior: smooth;
}
//You could also user ViewportScroller - available in angular
//.....
private _vps: ViewportScroller
scrollFn(anchor: string): void{
this._vps.scrollToAnchor(anchor)
}
//HTML
<p on-click="scrollFn('about')">scroll to about sections</p>
///About section
<div id="about">Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio, quasi nostrum labore sequi neque sed nihil consequuntur? Ea, dolorum minima,
cumque explicabo dicta est sit harum dolores, assumenda ex non.</div>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us