Scroll on anchor click #330
Answered
by
idiotWu
VottusCode
asked this question in
Q&A
-
Issue SummaryI'm not sure whether this is implemented, but I recently tried this library in one of my projects and foudn out that clicking on anchor links with hashes (eg href=#about-us) does not scroll. I've solved this issue with the code below. const bar = Scrollbar.init(document.querySelector('#my-scrollbar'));
bar.containerEl.querySelectorAll("a[href*='#']").forEach(el => {
el.addEventListener("click", () => {
bar.scrollIntoView(document.getElementById(el.getAttribute("href").substring(1)))
})
}) Expected BehaviorWhen clicked on such anchor tag, it should scroll to desired element. Online demohttps://codepan.egoist.sh/gist/5d0770947026e19d2e29585e70b57d4c |
Beta Was this translation helpful? Give feedback.
Answered by
idiotWu
Apr 11, 2021
Replies: 1 comment
-
See #128 (comment) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
idiotWu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See #128 (comment)