Last active
July 24, 2020 13:58
-
-
Save Protoff/2a22b8b3a211f61cdd6ff5dc3c94246b to your computer and use it in GitHub Desktop.
Плавная прокрутка к блоку
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// плавная прокрутка по якорю | |
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' | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Плавная прокрутка к нужному блоку на чистом JS