简体   繁体   English

使用 CSS 或 Javascript 平滑滚动

[英]Smooth scrolling with CSS or Javascript

My question is that in web page we should apply smooth scrolling with CSS or Javascript.我的问题是,在 web 页面中,我们应该使用 CSS 或 Javascript 应用平滑滚动。 I know how to do it with both, i just want to know that Which would be a better option?我知道如何使用两者,我只想知道哪个会是更好的选择?

Use css:使用 css:

scroll-behavior: smooth;滚动行为:平滑;

Use scroll-behavior property in the html element to enable smooth scrolling for the whole page.在 html 元素中使用 scroll-behavior 属性来启用整个页面的平滑滚动。

html {
  scroll-behavior: smooth;
}

Using JavaScript read this .使用 JavaScript 阅读

Please read this blog: https://www.lambdatest.com/blog/browser-compatible-smooth-scrolling-with-css-js-jquery/请阅读此博客: https://www.lambdatest.com/blog/browser-compatible-smooth-scrolling-with-css-js-jquery/

It might be helpful for you and determined which way is better for your requirements.它可能对您有所帮助,并确定哪种方式更适合您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM