哥们,你写错了.
应该是用pixelLeft
// JavaScript Document self.onError=null;
currentX = currentY = 0;
whichIt = null;
lastScrollX = 0; //最后离左边距离的负值
lastScrollY =0; //最后离顶部的高度的负值
//----------------------start fun秒执行一次
function heartBeat(id1,id2) {
diffY = document.body.scrollTop;
diffX = document.body.scrollLeft; if(diffY != lastScrollY) {
percent = .1 * (diffY - lastScrollY);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
id1.style.pixelTop += percent;
id2.style.pixelTop += percent;
lastScrollY = lastScrollY + percent;
} if(diffX != lastScrollX) {
percent = .1 * (diffX - lastScrollX);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
id1.style.pixelLeft += percent;
id2.style.pixelLeft += percent;
lastScrollX = lastScrollX + percent;
}
} scr=screen.width
left_1=(scr>800)?10:145
right_1=(scr>800)?1024:580 //左侧图片
document.write(" <div id=f1 style='left: "+left_1+"px; top: 150px; POSITION: absolute;'> <img src=newyear/2009newyear_left.jpg width=120 height=500 border=0> </div>") //右侧图片
document.write(" <div id=f2 style='left: "+right_1+"px; top: 150px; POSITION: absolute;'> <img src=newyear/2009newyear_right.jpg width=120 height=500 border=0> </div>")
action = window.setInterval("heartBeat(f1,f2)",50);
应该是用pixelLeft
// JavaScript Document self.onError=null;
currentX = currentY = 0;
whichIt = null;
lastScrollX = 0; //最后离左边距离的负值
lastScrollY =0; //最后离顶部的高度的负值
//----------------------start fun秒执行一次
function heartBeat(id1,id2) {
diffY = document.body.scrollTop;
diffX = document.body.scrollLeft; if(diffY != lastScrollY) {
percent = .1 * (diffY - lastScrollY);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
id1.style.pixelTop += percent;
id2.style.pixelTop += percent;
lastScrollY = lastScrollY + percent;
} if(diffX != lastScrollX) {
percent = .1 * (diffX - lastScrollX);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
id1.style.pixelLeft += percent;
id2.style.pixelLeft += percent;
lastScrollX = lastScrollX + percent;
}
} scr=screen.width
left_1=(scr>800)?10:145
right_1=(scr>800)?1024:580 //左侧图片
document.write(" <div id=f1 style='left: "+left_1+"px; top: 150px; POSITION: absolute;'> <img src=newyear/2009newyear_left.jpg width=120 height=500 border=0> </div>") //右侧图片
document.write(" <div id=f2 style='left: "+right_1+"px; top: 150px; POSITION: absolute;'> <img src=newyear/2009newyear_right.jpg width=120 height=500 border=0> </div>")
action = window.setInterval("heartBeat(f1,f2)",50);
id2.style.pixelLeft += percent;这两句写错了。
现在是实现了,不过,我想把这段改改
scr=screen.width
left_1=(scr>800)?10:145
right_1=(scr>800)?1024:580 变成按照 浏览器宽度来调整,而不是屏幕分辨率宽带
请大家指教