[英]How to make the transition to another section of a same page through clicking anchor tag (<a>) smoother in React?
I have only been able to make an instant jump to another section without transition.我只能在没有过渡的情况下立即跳转到另一个部分。 Here is how I do that:
我是这样做的:
<a href="#go_middle">Go Middle</a>
<div id="go_middle">Hello There</div>
I want to have transition effect, so it doesn't just instantly jump to the section, but rather a slower jump through another section of the page if there are any.我想要过渡效果,所以它不会立即跳转到该部分,而是在页面的另一个部分(如果有的话)中慢速跳转。
Add this to your CSS to the appropriate class or id.将此添加到您的 CSS 到适当的 class 或 id。
.scroll-div {
scroll-behavior: smooth;
}
You can also add it to the HTML tag directly.您也可以直接将其添加到 HTML 标签中。
html {
scroll-behavior: smooth;
}
This will make the page scroll smoothly to the right section, without jumps.这将使页面平滑地滚动到正确的部分,而不会跳转。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.