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

WBOY
Release: 2016-06-24 12:27:22
Original
1614 people have browsed it

在页面上加了对联广告后发现不滚动,找了N久才发现是这句导致不滚动的,可是如果去掉的话对于用DIV+CSS开发的网站来说又是灾难要另外找解决办法,应该是JS里有代码不符合W3C的标准

找了资料才知道是document.body不符合标准,换成document.documentElement就可以了,汗,纪念一下自己浪费的时间

本文转载自http://www.phpwind.net/read.php?tid=522770

以下为JS原文件,只要在首页调用就OK了。

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 = 84;// 左侧广告距离页首高度
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 = parseInt(y)");
eval("document.all." + layerName + ".style.posLeft = x");
setTimeout("MoveLeftLayer('AdLayer1');", 20);
}
function MoveRightLayer(layerName) {
var x = 5;
var y = 84;// 右侧广告距离页首高度
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);
}

document.write("

"
+" ");
initEcAd()

// JavaScript Document

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!