0

How to implement

element.scrollIntoView({behavior: 'smooth', block: "end", inline: "nearest"})

using widnow.scrollTo({behavior: 'smooth', top: ??})?

I have created some Sandbox. I need to scroll exactly the same position as using scrollIntoView

J. Doe
  • 502
  • 1
  • 7
  • 16
  • 1
    Safari doesn't support smooth scrolling on `.scrollTo()` either according to [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo#browser_compatibility). If you click the asterisk on the support table it displays: "Safari does not have support for the smooth scroll behavior." – DBS Aug 12 '22 at 15:42
  • Does this answer your question? [iOS Workaround: Smooth scrolling without the CSS property Scroll Behavior: Smooth?](https://stackoverflow.com/questions/59814404/ios-workaround-smooth-scrolling-without-the-css-property-scroll-behavior-smoot) – jsejcksn Aug 12 '22 at 15:48
  • @DBS you're right, smooth doesn't work in Safari... – J. Doe Aug 12 '22 at 16:16

1 Answers1

0

Based on this answer

const targetEl = document.getElementById('target');
 
window.scrollTo({
  behavior: 'smooth', 
  top: targetEl.offsetTop + targetEl.clientHeight - window.innerHeight
})
J. Doe
  • 502
  • 1
  • 7
  • 16