JavaScript element.scrollTop Property
You are Here:
JavaScript element.scrollTop Property
The element.scrollTop
property gets or sets the number of pixels that an element's content is scrolled vertically.
Note: An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<div id="outerDiv" onscroll="myFunction()">
<div id="innerDiv">Scroll me down and top</div>
</div>
<p id="point"></p>
<script>
var x = document.getElementById("point");
var elem = document.getElementById("outerDiv");
function myFunction(){
x.innerHTML = "scrollTop = " +elem.scrollTop;
}
</script>
</body>
</html>
Syntax
element.scrollTop
Return Values
Value | Explanation |
---|---|
Number | Returns the number of pixels that an element's content is scrolled vertically. |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.