smoothscroll.js 是一款纯 JS 页面平滑滚动插件。该js页面平滑滚动插件的特点是页面滚动的行为被作为 window 对象的扩展,用户可以通过 window 对象直接调用平滑滚动的方法。
window.scroll or window.scrollTo
window.scroll({ top: 2500, left: 0, behavior: 'smooth' });
window.scrollBy
window.scrollBy({ top: 100, left: 0, behavior: 'smooth' });
window.scrollBy
window.scrollBy({ top: -100, left: 0, behavior: 'smooth' });
element.scrollIntoView
document.querySelector('.hello').scrollIntoView({ behavior: 'smooth' });
element.scroll or element.scrollTo
element.scroll({ top: 0, left: 0, behavior: 'smooth' });
element.scrollBy
element.scrollBy({ top: 100, left: 0, behavior: 'smooth' });
Scroll to top
window.scroll({ top: 0, left: 0, behavior: 'smooth' });
or
document.querySelector('header').scrollIntoView({ behavior: 'smooth' });
官网地址 :http://iamdustan.com/smoothscroll/
GitHub 地址 :https://github.com/iamdustan/smoothscroll