对联广告

来源:互联网 发布:自动组词软件 编辑:程序博客网 时间:2024/04/30 08:26
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" text="text/html";charset="UTF-8">
    <title></title>
</head>
<body>
<script type="text/javascript">    
    var AD_left,AD_right;
    function initAD(){
        AD_left = document.getElementById("AD_left");
        AD_right = document.getElementById("AD_right");
        AD_left.style.visibility = "visible";
        AD_left.style.position = "absolute";
        AD_left.style.zIndex = 1;
        AD_right.style.visibility = "visible";
        AD_right.style.position = "absolute";
        //zIndex表示层叠顺序,默认值为0,值越大表示离用户越近。
        //zIndex只对定位元素有效
        AD_right.style.zIndex = 1;
        //setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式
        //通过不断地执行moveAD(),使图片位于网页两侧
        setTimeout("moveAD(AD_left)",20);
        setTimeout("moveAD(AD_right)",20);

    }
    function moveAD(ADName){
        var x = 500;
        var y = 340;
        var diff = (document.body.scrollTop + y - ADName.style.posTop)*30;
        var y = document.body.scrollTop + y - diff;
        ADName.style.top = y + "px";//图片距顶部的距离
        if (ADName == AD_left) {
            ADName.style.left = x + "px";
        }
        if (ADName == AD_right) {
            ADName.style.right = x + "px";//图片距左右两侧的距离
        }
    }
    function closeAD(ADName){
        ADName.parentNode.style.visibility="hidden";
    }
    document.write("<div id='AD_left'>");
    document.write("<img src='img/1.jpg' width='134px' height='20px' onclick='javascript:closeAD(this);void(0);'style='display:block' />");
    document.write("<img src='img/2.jpg' width='134px' height='200px'/>");
    document.write("</div>")
    document.write("<div id='AD_right' style='display:block;right:0px'>");
    document.write("<img src='img/1.jpg' width='134px' height='20px' onclick='javascript:closeAD(this);void(0);'style='display:block' />");
    document.write("<img src='img/3.jpg' width='134px' height='200px'/>");
    document.write("</div>");
    initAD();
</script>
</body>
</html>
0 0