[英]How to make smooth onscroll effect
您可以将此添加到您的 CSS:
html {
scroll-behavior: smooth;
}
或者,您可以根据需要以三种不同的方式将其与 javascript 一起添加:
// goes to specific height position at 2500 pixels:
window.scroll({
top: 2500,
left: 0,
behavior: 'smooth'
});
// scrolls 100 pixels from the current position:
window.scrollBy({
top: 100, // could be negative value
left: 0,
behavior: 'smooth'
});
// scrolls to an element with class .hello:
document.querySelector('.hello').scrollIntoView({
behavior: 'smooth'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.