I'm using JS to smooth scroll using anchor tags and IDs, and I'd like to adjust the duration of the smooth scroll animation.
Here's my code:
let anchorlinks = document.querySelectorAll('a[href^="#"]')
for (let item of anchorlinks) {
item.addEventListener('click', (e)=> {
let hashval = item.getAttribute('href')
let target = document.querySelector(hashval)
target.scrollIntoView({
behavior: 'smooth',
block: 'start',
duration: 200
})
history.pushState(null, null, hashval)
e.preventDefault()
})
}
However, it still uses the default duration. I can't figure out any way to adjust the duration fo the animation.
Thanks!