Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the difference between the scrollX and pageXOffset

Tags:

javascript

Are the following methods same?

window.scrollX  === window.pageXOffset

window.scrollY  === window.pageYOffset

If there is no difference, why two methods are introduced?

like image 478
Bhojendra Rauniyar Avatar asked Dec 26 '22 10:12

Bhojendra Rauniyar


1 Answers

From MDN:

The pageXOffset property is an alias for the scrollX property:

window.pageXOffset == window.scrollX; // always true 

For cross-browser compatibility, use window.pageXOffset instead of window.scrollX. Additionally, older versions of Internet Explorer (< 9) do not support either property and must be worked around by checking other non-standard properties.

Same thing goes for scrollY and pageYOffset.

Source: https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollX

like image 59
Wayne Avatar answered Dec 28 '22 05:12

Wayne