我想要的结果是广告位置固定在一个位置,不随页面动!请高手详细解答,最好给我写上代码,因为我是外行。
function initEcAd() {
document.all.AdLayer1.style.posTop = -200;
document.all.AdLayer1.style.visibility = 'visible'
document.all.AdLayer2.style.posTop = -200;
document.all.AdLayer2.style.visibility = 'visible'
MoveLeftLayer('AdLayer1');
MoveRightLayer('AdLayer2');
}
function MoveLeftLayer(layerName) {
var x = 5;
var y = 100;// 左侧广告距离页首高度
var diff = (document.body.scrollTop + y - document.all.AdLayer1.style.posTop)*.40;
var y = document.body.scrollTop + y - diff;
eval("document.all." + layerName + ".style.posTop = parseInt(y)");
eval("document.all." + layerName + ".style.posLeft = x");
setTimeout("MoveLeftLayer('AdLayer1');", 20);
}
function MoveRightLayer(layerName) {
var x = 5;
var y = 100;// 右侧广告距离页首高度
var diff = (document.body.scrollTop + y - document.all.AdLayer2.style.posTop)*.40;
var y = document.body.scrollTop + y - diff;
eval("document.all." + layerName + ".style.posTop = y");
eval("document.all." + layerName + ".style.posRight = x");
setTimeout("MoveRightLayer('AdLayer2');", 20);
}
if(screen.width>800)
{
document.write("<div id=AdLayer1 style='position: absolute; left:15px; top:100px;visibility:hidden;z-index:1'><a href='http://www.baidu.com'
target='_blank'><img src=/pic/2008wp.gif border='0'></a></div>"
+"<div id=AdLayer2 style='position: absolute;visibility:hidden;z-index:1'><a href='http://www.baidu.com' target='_blank'><img
src=/pic/2008wp.gif border='0'></a></div>");
initEcAd()
}
我试了一下,还是会变,求帮忙!!!
追答不应该的。他随广告页面变动主要是setTimeout("MoveRightLayer('AdLayer2');", 20)、setTimeout("MoveLeftLayer('AdLayer1');", 20);这两句话起作用不断调用以改变广告位置。只要去掉这两句就不应该动了。可能是你浏览器有缓存还是你的页面有缓存机制?只要去掉就应该动不了。。我也只能帮你这么多。。