Scroll event

Can Avcı
Dec 14, 2022

Dom elements have their current scroll state in their scrollLeft/scrollTop properties.

document.documentElement.scrollLeft/scrollTop works in most browsers
Luckily, we dont have to remember this verbose at all

alert('Current scroll from the top: ' + window.pageYOffset);
alert('Current scroll from the left: ' + window.pageXOffset);

regular elements can be scrolled by changing scrollTop/scrollLeft.
Alternativelt there is a simpler and universal method exists
window.scrollBy(x,y) : scrolls the page relative to its current position window.scrollTo(pageX,pageY) : scrolls the page to absolute coordinates

--

--