当前位置:首页 > DIV+CSS教程 > 正文

div+css下js对联广告不随屏幕滚动的解决方法

作者:gh8510 来源:hi.baidu.com 【 】 浏览: 添加日期:2009-05-21 我要评论(1)     

在页面上加了对联广告后发现不滚动,找了N久才发现是<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">这句导致不滚动的,可是如果去掉的话对于用DIV+CSS开发的网站来说又是灾难要另外找解决办法,应该是JS里有代码不符合W3C的标准

找了资料才知道是document.body不符合标准,换成document.documentElement就可以了.以下为JS原文件,只要在首页调用就OK了。

<SCRIPT FOR='xuangua' EVENT='fscommand()' LANGUAGE='JavaScript'>
AdLayer1.style.visibility='hidden';
AdLayer2.style.visibility='hidden';
</script>
<script LANGUAGE='JavaScript'>
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'
//document.all.AdLayer3.style.posTop = -600;
//document.all.AdLayer3.style.visibility = 'visible'

MoveLeftLayer('AdLayer1');
MoveRightLayer('AdLayer2');

//MoveRightbuttonLayer('AdLayer3');
}
function MoveLeftLayer(layerName) {
var x = 5;
var y = 100;
var diff = (document.documentElement.scrollTop + y - document.all.AdLayer1.style.posTop)*.40;
var y = document.documentElement.scrollTop + y - diff;
if(screen.height<768){
var y = 50;
var diff = (document.documentElement.scrollTop + y - document.all.AdLayer1.style.posTop)*.40;
var y = document.documentElement.scrollTop + y - diff;
}
eval("document.all." + layerName + ".style.posTop = y");
eval("document.all." + layerName + ".style.posLeft = x");
setTimeout("MoveLeftLayer('AdLayer1');", 20);
}
function MoveRightLayer(layerName) {
var x = 5;
var y = 100;
var diff = (document.documentElement.scrollTop + y - document.all.AdLayer2.style.posTop)*.40;
var y = document.documentElement.scrollTop + y - diff;
if(screen.height<768){
var y = 5;
var diff = (document.documentElement.scrollTop + y - document.all.AdLayer2.style.posTop)*.40;
var y = document.documentElement.scrollTop + y - diff;
}
eval("document.all." + layerName + ".style.posTop = y");
eval("document.all." + layerName + ".style.posRight = x");
setTimeout("MoveRightLayer('AdLayer2');", 20);
}
function MoveRightbuttonLayer(layerName) {
var x = 5;
var y = 475;
var diff = (document.documentElement.scrollTop + y - document.all.AdLayer3.style.posTop)*.40;
var y = document.documentElement.scrollTop + y - diff;
if(screen.height<768){
var y = 310;
var diff = (document.documentElement.scrollTop + y - document.all.AdLayer3.style.posTop)*.40;
var y = document.documentElement.scrollTop + y - diff;
}
eval("document.all." + layerName + ".style.posTop = y");
eval("document.all." + layerName + ".style.posRight = x");
setTimeout("MoveRightbuttonLayer('AdLayer3');", 20);
}
</script>

<script language='JavaScript'>
document.write("<div id=AdLayer1 style='position: absolute;visibility:hidden;z-index:1'><EMBED src='images/duilian.swf' quality=high WIDTH=100 HEIGHT=300 TYPE='application/x-shockwave-flash' id=xuangua></EMBED></div>"
+"<div id=AdLayer2 style='position: absolute;visibility:hidden;z-index:1'><EMBED src='images/duilian.swf' quality=high WIDTH=100 HEIGHT=300 pluginspage='http://www.macromedia.com/go/getflashplayer' TYPE='application/x-shockwave-flash' id=xuangua></EMBED></div>");
initEcAd()
</script>
 

(如果您觉得本站不错,请告诉身边的朋友,或转载到论坛、百度知道、贴吧等,记得带网址哟,不胜感激!)

〖DIV+CSS教程〗Tags: js 对联广告 浮动 随屏滚动

更多评论(1)..会员评论

ua(123.5.*.*) 发表于:2009-10-12 12:21:18
这个也不行吧?document.allall似乎只有IE认得。

出差旅游免费预订酒店

【视频教程】新手常见问题