Home >Web Front-end >HTML Tutorial >Solution to js couplet ads not scrolling with the screen under div css_html/css_WEB-ITnose
" http://www.w3.org/TR/html4/loose.dtd">This sentence causes no scrolling, but if it is removed, it will be a disaster for websites developed with DIV CSS. We need to find another solution. There is some code in JS that does not comply with W3C standards
After looking for information, I found out that document.body does not meet the standards. Just replace it with document.documentElement. I wish I could commemorate the time I wasted
This article is reproduced from http://www.phpwind.net/read.php?tid=522770
The following is the original JS file, as long as it is called on the homepage, it will be 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;//Height of the left ad from the top of the page
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;//Height of the right ad from the top of the page
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("< ;div id=AdLayer1 style='position: absolute;visibility:hidden;z-index:1'>< img src='/images/float.jpg' border='0' width=106 height=300>
  ; ×
// JavaScript Document