Skip to content

Instantly share code, notes, and snippets.

@Protoff
Last active July 24, 2020 13:58
Show Gist options
  • Save Protoff/2a22b8b3a211f61cdd6ff5dc3c94246b to your computer and use it in GitHub Desktop.
Save Protoff/2a22b8b3a211f61cdd6ff5dc3c94246b to your computer and use it in GitHub Desktop.
Плавная прокрутка к блоку
// плавная прокрутка по якорю
const scrollTo_Anchors = document.querySelectorAll('a[href^="#"]')
for (let scrollTo_Anchor of scrollTo_Anchors) {
scrollTo_Anchor.addEventListener('click', function (e) {
e.preventDefault()
const scrollTo_ID = scrollTo_Anchor.getAttribute('href').substr(1)
document.getElementById(scrollTo_ID).scrollIntoView({
behavior: 'smooth',
block: 'start'
})
})
}
@Protoff
Copy link
Author

Protoff commented Apr 27, 2020

Плавная прокрутка к нужному блоку на чистом JS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment