0

I need to run a function once smooth scrolling to an element in my page is complete. JavaScript's function scrollTo doesn't seem to support a fallback function though.

Is it no feasible then?

window.scrollTo({
  top: elementLocation,
  left: 0,
  behavior: 'smooth'
})
myFunction();
drake035
  • 3,955
  • 41
  • 119
  • 229

1 Answers1

-1

Try this:

const position = 500

window.scrollTo({
  top: position,
  left: 0,
  behavior: 'smooth'
})

setTimeout(() => console.log('scrolled'), position)
Mark Minerov
  • 309
  • 1
  • 8