Created
November 29, 2010 21:42
-
-
Save jbail/720683 to your computer and use it in GitHub Desktop.
Accessing scroll properties in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var square = document.getElementById("square"); | |
var content = document.getElementById("content"); | |
/* | |
* Vertical y-axis properties | |
*/ | |
square.offsetHeight; //the height in pixels of the scrollable element (e.g. 150px) | |
square.scrollTop; //the number of pixels from the top that the element is scrolled (e.g. 350px) | |
content.scrollHeight; //the total height in pixels of the scrollable content (e.g. 500px) | |
/* | |
* Horizontal x-axis properties | |
*/ | |
square.offsetWidth; //the width in pixels of the scrollable element (e.g. 150px) | |
square.scrollLeft; //the number of pixels from the left that the element is scrolled (e.g. 350px) | |
content.scrollWidth; //the total width in pixels of the scrollable content (e.g. 500px) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment