Skip to content

Instantly share code, notes, and snippets.

@dvygolov
Last active July 20, 2021 09:55
Show Gist options
  • Save dvygolov/75270c5e57a1b0dc0f6e6402206bb8d7 to your computer and use it in GitHub Desktop.
Save dvygolov/75270c5e57a1b0dc0f6e6402206bb8d7 to your computer and use it in GitHub Desktop.
<script>
document.addEventListener('DOMContentLoaded', function() {
const anchors = document.querySelectorAll('a[href*="#"]')
for (let anchor of anchors) {
anchor.removeAttribute('onclick');
anchor.addEventListener('click', function (e) {
e.preventDefault()
const blockID = anchor.getAttribute('href').substr(1)
document.getElementById(blockID).scrollIntoView({
behavior: 'smooth',
block: 'start'
})
})
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment