JavaScript Tutorial/Style/top
div.style.top="100px";
<source lang="javascript">
<html> <head> <title>PrettyPretty</title> <script type="text/javascript"> document.onclick=changeElement; function changeElement() {
var div = document.getElementById("div1"); div.style.backgroundColor="#00f"; div.style.width="500px"; div.style.color="#fff"; div.style.height="200px"; div.style.paddingLeft="50px"; div.style.paddingTop="50px"; div.style.fontFamily="Verdana"; div.style.fontSize="2em"; div.style.border="3px dashed #ff0"; div.style.position="absolute"; div.style.left="200px"; div.style.top="100px"; div.style.textDecoration="underline";
} </script> </head> <body>
This is a DIV element. Click me to see the change.
</body> </html></source>
Set div position in page scroll action
<source lang="javascript">
<html>
<head> <title>OnScroll Example</title> <script type="text/javascript"> window.onscroll = function () { var oWatermark = document.getElementById("divWatermark"); oWatermark.style.top = document.body.scrollTop; } </script> </head> <body>
Try scrolling this window.
www.wbex.ru
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
</body>
</html></source>