/

HTML / CSS / JavaScript Tutorial

JavaScript Window property: scrollX

[this page | pdf | back links]

The scrollX property (of the JavaScript BOM window object) is an alias for the for pageXOffset property.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body onresize="myOnresize()">
try moving window and then resizing it
<br><br>
Window page offset: <b id="pageOffset"></b><br>
Window scroll: <b id="scroll"></b><br>
Window screen (Left|Top|X|Y): <b id="screen"></b><br>

<script>
function myOnresize() {
  var x = window.pageXOffset;
  var y = window.pageYOffset;
  document.getElementById("pageOffset").innerHTML = 
    x + " x " + y;
  x = window.scrollX;
  y = window.scrollY;
  document.getElementById("scroll").innerHTML =
    x + " x " + y;
  document.getElementById("screen").innerHTML =
    window.screenLeft + "|" +
    window.screenTop + "|" +
    window.screenX + "|" +
    window.screenY;
}
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile