How to implement
JavaScript
x
2
1
element.scrollIntoView({behavior: 'smooth', block: "end", inline: "nearest"})
2
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
JavaScript
1
7
1
const targetEl = document.getElementById('target');
2
3
window.scrollTo({
4
behavior: 'smooth',
5
top: targetEl.offsetTop + targetEl.clientHeight - window.innerHeight
6
})
7