简体   繁体   English

如何设置到 .scrollIntoView 行为的定时过渡:平滑?

[英]How to set a timed transition to the .scrollIntoView behavior: smooth?

This is my code:这是我的代码:

    document.querySelector(#theId).scrollIntoView({
      behavior: "smooth",
    });

I have gone to the documentation of scrollIntoView and I don't seem to find a way to set the speed of the smooth transition.我已经查看了scrollIntoView的文档, 似乎没有找到设置平滑过渡速度的方法。 I would ideally like to set a time in milliseconds to tell the browser the duration the scroll must last (just like it can be done with the transition property in CSS).理想情况下,我想设置一个以毫秒为单位的时间来告诉浏览器滚动必须持续的持续时间(就像可以使用 CSS 中的 transition 属性来完成一样)。 Do you know if there is a workaround to achieve this?你知道是否有解决方法来实现这一目标? Thank you so much.非常感谢。

There is no way to change the scrolling speed with scrollIntoView() .无法使用scrollIntoView()更改滚动速度。 See the smooth scroll specification :请参阅平滑滚动规范

When a user agent is to perform a smooth scroll of a scrolling box box to position, it must update the scroll position of box in a user-agent-defined fashion over a user-agent-defined amount of time .当用户代理要执行滚动框框的平滑滚动以定位时,它必须在用户代理定义的时间量内以用户代理定义的方式更新框的滚动位置。

But I also don't see any reason why you would want to do that.但我也看不出你为什么要这样做。 But if you insist on changing it, you have to do it manually .但是如果你执意要改,就得手动改了

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

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