// 获取目标元素 const tableSection = document.querySelector('.data-table-section') // 平滑滚动到目标元素 tableSection.scrollIntoView({ behavior: 'smooth', block: 'start' })
青云直上三千码
// 获取目标元素 const tableSection = document.querySelector('.data-table-section') // 平滑滚动到目标元素 tableSection.scrollIntoView({ behavior: 'smooth', block: 'start' })
document.querySelector('.data-table-section') 获取到目标 DOM 元素scrollIntoView() 方法,并传入配置对象:
behavior: 'smooth':指定滚动方式为平滑过渡(默认是 auto 即时跳转)block: 'start':设置元素与可视区域的垂直对齐方式为顶部对齐(可选值还有 center、end、nearest)