Skip to content

Instantly share code, notes, and snippets.

@Megafry
Created May 7, 2025 13:29
Show Gist options
  • Save Megafry/2c1f7a733f734d690f3a094718874a1a to your computer and use it in GitHub Desktop.
Save Megafry/2c1f7a733f734d690f3a094718874a1a to your computer and use it in GitHub Desktop.
Stop using window.scrollTo(), Use the new scrollIntoView, this will also take into consideration the scroll-padding defined in CSS.
button.addEventListener('click', e => {
const targetEl = document.getElementById("footer")
targetEl.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'start'})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment