日期:2014-05-17  浏览次数:20456 次

滚动条如何控制层的移动
滚动条如何控制层的移动



------解决方案--------------------
JScript code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
        var b = document.documentElement||document.body;
        var divPositionTop = 100,ST=0,Temp=0;
        function SetDiv(obj){
            var divTop = parseInt(obj.style.top);
            ST = b.scrollTop;
            if(divPositionTop+ST!=divTop){
                Temp=Math.ceil((divPositionTop+ST-divTop)*0.1);
                obj.style.top=(divTop+Temp)+"px"
            }
        }
        window.onload = function(){
            var obj = document.getElementById("test");
            setInterval(function(){SetDiv(obj)},10)
        }
    </script>
</head>
<body style="height:2000px;">
    <div id="test" style="position:absolute;top:100px;right:10px;background:#000;width:100px;height:100px"></div>
</body>
</html>