Menu

gitpiper

smoothScroll javascript Code Snippet in 2024

browsercssintermediate

Last Updated: 3 December 2024

Smoothly scrolls the element on which it's called into the visible area of the browser window.

  • Use Element.scrollIntoView() to scroll the element.
  • Use { behavior: 'smooth' } to scroll smoothly.
const smoothScroll = element => document.querySelector(element).scrollIntoView({ behavior: 'smooth' });
smoothScroll('#fooBar'); // scrolls smoothly to the element with the id fooBar smoothScroll('.fooBar'); // scrolls smoothly to the first element with a class of fooBar

javascript snippet similar to smoothScroll For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️