$('.btn').on('click', function (e) { if (this.hash != '') { e.preventDefault(); const hash = this.hash; $('html, body').animate( { scrollTop: $(hash).offset().top, }, 800 ); } });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter