讓圖片在頁面中飄浮



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title></title>
    <style type="text/css">
        .floatCla{
            position: absolute;
            z-index: 99;
        }
    </style>
    <script type="text/javascript">
        var directionY= 0;
        var directionX= 0;
        var moveX = 0;
        var moveY =0 ;
        var step = 1;
        function $(id){
            return document.getElementById(id);
        }
        function changePos(){
            var height = document.documentElement.clientHeight;
            var width = document.documentElement.clientWidth;
            var imgHeight = $("floatImg").height;
            var imgWidth = $("floatImg").width;
            var floatDiv = $("float");
            if(directionY ==0){
                moveY+=step;
            }else{
                moveY-=step;
            }
            if(moveY>=(height-imgHeight)){


                directionY=1;
                moveY = height-imgHeight;
            }
            if(moveY<0){
                directionY = 0;
                moveY = 0;
            }
            if(directionX ==0){
                moveX+=step;
            }else{
                moveX-=step;
            }
            if(moveX>=(width-imgWidth)){


                directionX=1;
                moveX = width-imgWidth;
            }
            if(moveX<0){
                directionX = 0;
                moveX = 0;
            }
            document.title = moveY+"---"+height;
            floatDiv.style.top = moveY +parseInt(document.documentElement.scrollTop)+"px";
            floatDiv.style.left = moveX +parseInt(document.documentElement.scrollLeft)+"px";
        }
        setInterval("changePos()",10);
    </script>
</head>
<body>
<div id ="float" class="floatCla">
    <img id="floatImg" src="images/187480_205.jpg">
</div>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章