Rob*_*son 5 javascript animation duration smooth-scrolling
我使用 JS 使用锚标记和 ID 来平滑滚动,并且我想调整平滑滚动动画的持续时间。
这是我的代码:
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()
})
}Run Code Online (Sandbox Code Playgroud)
但是,它仍然使用默认的持续时间。我想不出任何方法来调整动画的持续时间。
谢谢!
| 归档时间: |
|
| 查看次数: |
598 次 |
| 最近记录: |