Set div position in page scroll action : top « Style « JavaScript Tutorial






<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>
         <P>Try scrolling this window.</p>
         <div id="divWatermark" style="position: absolute; top: 0px; right: 0px; color: #cccccc; width: 150px; height: 30px; background-color: navy">www.java2s.com</div>
         <P>Line 1</p>
         <P>Line 2</p>
         <P>Line 3</p>
         <P>Line 4</p>
         <P>Line 5</p>
         <P>Line 6</p>
         <P>Line 7</p>
         <P>Line 8</p>
         <P>Line 9</p>
         <P>Line 10</p>
         <P>Line 11</p>
         <P>Line 12</p>
    </body>
</html>








22.15.top
22.15.1.Set div position in page scroll action
22.15.2.div.style.top="100px";