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
Advertisement
Answer
Based on this answer
const targetEl = document.getElementById('target');
window.scrollTo({
behavior: 'smooth',
top: targetEl.offsetTop + targetEl.clientHeight - window.innerHeight
})