2

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. 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). Do you know if there is a workaround to achieve this? Thank you so much.

1 Answer 1

1

There is no way to change the scrolling speed with 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.

Sign up to request clarification or add additional context in comments.

2 Comments

"But I also don't see any reason why you would want to do that". I would want to do that to specify the animation time based on other application-specific requirements.
The reason the OP wants to do that is quite obvious to be honest. This is still an animation for which it is a nice feature to have control on duration and/or easing. And to be quite frank the default value of most browsers is way too fast for a default value. It feels almost worse than instantly moving down.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.