javascript常用属性

来源:互联网 发布:爱普生打印机清零软件 编辑:程序博客网 时间:2024/05/16 08:02
document.body.clientWidth  1004   客户端浏览器的宽度
document.body.clientHeight  598    客户端浏览器的高度


document.body.scrollLeft 0         若有滚动条,则代表距左端的距离
document.body.scrollTop 0         若有滚动条,则代表距上端的距离


document.body.scrollWidth 1004    若有滚动条,滚动条的宽度
document.body.scrollHeight 652     若有滚动条,滚动条的高度


下面代码是一个例子,在页上走动的小广告




  




        <DIV id="img" style="LEFT: 0px; WIDTH: 99px; POSITION: absolute; TOP: 1582px; HEIGHT: 24px">
            <img src="images\ask.gif" width="50" height="50">
        </DIV>
        <SCRIPT language="JavaScript"> 
        
       
            var xPos = 20; 
            var yPos = document.body.clientHeight; 
            var step = 50; 
            var delay = 2000;
            var height = 0; 
            var Hoffset = 0; 
            var Woffset = 0; 
            var yon = 0; 
            var xon = 0; 
            var pause = true; 
            var interval; 
            img.style.top = yPos;   
                        
            
                
            function changePos() { 


                alert(document.body.clientHeight);
                alert(document.body.clientWidth);
                alert(document.body.scrollLeft);
                alert(document.body.scrollTop);
                alert(document.body.scrollWidth);
                alert(document.body.scrollHeight);
                
                //alert(Hoffset);
                //alert(Woffset);
            
                width = document.body.clientWidth; 
                height = document.body.clientHeight; 
                Hoffset = img.offsetHeight; //不变54
                Woffset = img.offsetWidth; //不变99
                img.style.left = xPos + document.body.scrollLeft; 
                img.style.top = yPos + document.body.scrollTop; 
               
                if (yon) { 
                    yPos = yPos + step; 
                } else { 
                    yPos = yPos - step; 
                } 
                if (yPos < 0) { 
                    yon = 1; 
                    yPos = 0; 
                } 
                if (yPos >= (height - Hoffset)) { 
                    yon = 0; 
                    yPos = (height - Hoffset); 
                } 


                if (xon) { 
                    xPos = xPos + step; 
                } 
                else { 
                    xPos = xPos - step; 
                } 
                if (xPos < 0) { 
                    xon = 1; 
                    xPos = 0; 
                } 
                if (xPos >= (width - Woffset)) { 
                    xon = 0; 
                    xPos = (width - Woffset); 
                } 
            } 


            function start() { 
                img.visibility = "visible"; 
                interval = setInterval('changePos()', delay); 
            } 
            start(); 
        </SCRIPT>
0 0
原创粉丝点击