1

I'm trying to scroll to element smoothly,but can't find a way to control the scroll time without jquery.

I found two ways to scroll to element smoothly:

  1. document.getElementById(targetElementId).scrollIntoView({behavior:'smooth'})

2.$('html, body').animate({scrollTop: $(selector).offset().top},1000)

The second way uses jquery and easy to control scroll time.

But I wonder if there a way in native javascript to control the scroll time.

Thank you

冯克勤
  • 37
  • 5

1 Answers1

0

use this function :

Smooth scroll anchor links WITHOUT jQuery

Scroll time is used as parameter.

user2267379
  • 1,067
  • 2
  • 10
  • 20