当我的网站加载时,我使用以下 JavaScript 动画使一些图像从屏幕右侧滑入:
var step=8; var step1=16; var step2=12; var step3=6; var step4=4;
function move_img(str) {
var a=document.getElementById('i1').offsetTop; a= a +100;
document.getElementById('i1').style.top= a + "px";
var b=document.getElementById('i2').offsetTop; b= b +100;
document.getElementById('i2').style.top= b + "px";
var c=document.getElementById('i3').offsetTop; c= c +100;
document.getElementById('i3').style.top= c + "px";
var d=document.getElementById('i4').offsetTop; d= d +100;
document.getElementById('i4').style.top= d + "px";
var e=document.getElementById('i5').offsetTop; e= e +100;
document.getElementById('i5').style.top= e + "px"; }
function disp(){
var a=document.getElementById('i1').offsetLeft; var
b=document.getElementById('i2').offsetLeft; var
c=document.getElementById('i3').offsetLeft; var
d=document.getElementById('i4').offsetLeft; var
e=document.getElementById('i5').offsetLeft; if(a > 400){a= a - step;
document.getElementById('i1').style.left= a + "px"; // horizontal
movment step *=0.9948; } if(b > 200 ){b= b - step1;
document.getElementById('i2').style.left= b + "px"; // horizontal
movment step1*=0.992; }
if(c > 350 ){c = c - step2; document.getElementById('i3').style.left=
c + "px"; // horizontal movment step2*=0.993; }
if(d > 1200 ){d = d - step3; document.getElementById('i4').style.left=
d + "px"; // horizontal movment step3*=0.997; } if(e > 1350 ){e = e -
step4; document.getElementById('i5').style.left= e + "px"; //
horizontal movment step4*=0.998; } }
function timer(){ disp(); my_time=setTimeout('timer()',10);
}
虽然这在我的电脑上看起来很棒,因为它使用像素而不是百分比,但在不同的纵横比下看起来很糟糕。我怎样才能解决这个问题?
谢谢!