Js 滚动

 

 1function getPosition() {
 2    var top    = document.body.scrollTop;  
 3    var left   = document.body.scrollLeft;
 4    var height = document.body.clientHeight;
 5    var width  = document.body.clientWidth;
 6    return {top:top,left:left,height:height,width:width};
 7}

 8
 9function showDiv(){
10    var width  = 50;  //弹出框的宽度
11    var height = 200;  //弹出框的高度
12    
13    var leftDiv    = document.getElementById("leftDiv");
14    leftDiv.style.display  = "block";
15    leftDiv.style.position = "absolute";
16    leftDiv.style.zindex   = "999";
17    leftDiv.style.width    = width + "px";
18    leftDiv.style.height   = height + "px";
19    var Position = getPosition();
20    leftadd = (Position.width-width)/2;
21    topadd  = (Position.height-height)/2;
22    leftDiv.style.top  = (Position.top  + 10)  + "px";
23    leftDiv.style.left = 20 + "px";
24    
25    //右边的     层
26    var rightDiv    = document.getElementById("rightDiv");
27    rightDiv.style.display  = "block";
28    rightDiv.style.position = "absolute";
29    rightDiv.style.zindex   = "999";
30    rightDiv.style.width    = width + "px";
31    rightDiv.style.height   = height + "px";
32    var Position = getPosition();
33    leftadd = (Position.width-width)/2;
34    topadd  = (Position.height-height)/2;
35    rightDiv.style.top  = (Position.top  + 10)  + "px";
36    rightDiv.style.left = (Position.width-100+ "px";
37    
38    window.onscroll = function (){        
39        var Position   = getPosition();
40        leftDiv.style.top  = (Position.top  + 10)  +"px";
41        leftDiv.style.left = 20+"px";
42        //alert(Position.top);
43        rightDiv.style.top  = (Position.top  + 10)  +"px";
44        rightDiv.style.left = (Position.width-100+"px";
45    }
;
46    
47}

48

 

posted on 2009-01-19 18:00  rubys  阅读(226)  评论(0)    收藏  举报