setTimeout("MoveLayer('AdLayer1');", 20);//设置20毫秒后再调用函数MoveLayer() MoveLayer() 不存在

解决方案 »

  1.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>为网页添加浮动广告</title>
    </head>
    <body>
    <!--下面为一个ID为AdLayer的层(如ID名不为AdLayer,
    上面MoveLayer()内的AdLayer也要作相应修改),包括一张带链接的图片-->
    <div id='AdLayer1' style='position:absolute; width:61px; height:59px; z-index:20; visibility:hidden;; left: 600px; top: 300px'>
    <a href="http://www.jkqcw.cn/jsxxll.asp">
    <img src='../20041121115643.jpg' border="0" height="60" width="60"></a>
    </div>
    <div id='AdLayer2' style='position:absolute; width:61px; height:59px; z-index:20; visibility:hidden;; left: 600px; top: 300px'>
    <a href="http://www.jkqcw.cn/jsxxll.asp">
    <img src='../black.jpg' border="0" height="60" width="60"></a>
    </div>
    <SCRIPT FOR=window EVENT=onload LANGUAGE="JavaScript">
    initAd();//载入页面后,调用函数initAd()
    </SCRIPT>
    <script language="JavaScript">
    function initAd() {
    document.all.AdLayer1.style.posTop = -200;
    document.all.AdLayer1.style.visibility = 'visible'
    document.all.AdLayer2.style.posTop = -200;
    document.all.AdLayer2.style.visibility = 'visible'
    //设置onLoad事件激发以后,广告层相对于固定后的y方向位置
    //document.all.AdLayer.style.visibility = 'visible'//设置层为可见
    MoveLeftLayer('AdLayer1');
    MoveRightLayer('AdLayer2');//调用函数MoveLayer()
    }
    function MoveLeftLayer(layerName) {
    var x=30;
    //var x = 790;//浮动广告层固定于浏览器的x方向位置
    var y = 200 ;//浮动广告层固定于浏览器的y方向位置
    var diff = (document.body.scrollTop + y - document.all.AdLayer1.style.posTop)*.40;
    var y = document.body.scrollTop + y - diff;
    document.all(layerName).style.posTop = y;
    document.all(layerName).style.posLeft = x;//移动广告层
    setTimeout("MoveLeftLayer('AdLayer1');", 20);//设置20毫秒后再调用函数MoveLayer()
    }
    function MoveRightLayer(layerName) {
    var x=window.screen.width-100;
    //var x = 790;//浮动广告层固定于浏览器的x方向位置
    var y = 200 ;//浮动广告层固定于浏览器的y方向位置
    var diff = (document.body.scrollTop + y - document.all.AdLayer2.style.posTop)*.40;
    var y = document.body.scrollTop + y - diff;
    document.all(layerName).style.posTop = y;
    document.all(layerName).style.posLeft = x;//移动广告层
    setTimeout("MoveRightLayer('AdLayer2');", 20);//设置20毫秒后再调用函数MoveLayer()
    }
    </script>
    </body>