本文範例講述了js實作飛入星星特效程式碼,分享給大家供大家參考。
具體實作程式碼如下:
星空極速飛入效果
');
}
document.write('');
function Set(){
for (i=0; i
transfer(i)
xF[i]=xW/14;
}
}
function Assign(){
sdiv.style.top=document.body.scrollTop;
for (i=0; i
xF[i]-=xS[i]*25;
if (xF[i]
div[i].style.top =xY[i];
div[i].style.left=xX[i];
div[i].style.fontSize=xF[i];
}
}
function fly(){
xMY=window.document.body.clientHeight/2;
xMX=window.document.body.clientWidth/2;
xWd=Math.round(Math.random()*40 5);
xHd=Math.round(Math.random()*30 5);
for (i=0; i
xY[i]=xA[i] =(xMY-xA[i])*(xS[i]);
xX[i]=xB[i] =(xMX-xB[i])*(xS[i]);
if ((xX[i] > xMX-xWd) && (xX[i] xMY-xHd) && (xY[i]
transfer(i)
}
if ((xX[i]xW)||(xY[i]xH)){
xF[i]=xW/14;
}
}
Assign();
setTimeout('fly()',1);
}
function transfer(i){
xH=window.document.body.offsetHeight;
xW=window.document.body.offsetWidth;
xA[i]=Math.round(Math.random()*xH);
xB[i]=Math.round(Math.random()*xW);
xS[i]=Math.random()*0.05 0.05;
xR=Math.round(Math.random()*3);
xE=Math.round(Math.random()*50 50);
if (xR == 3) xB[i]=-xE;
if (xR == 2) xB[i]=xW xE;
if (xR == 1) xA[i]=-xE;
if (xR == 0) xA[i]=xH;
}
Set();
fly();
希望本文所述對大家的javascript程式設計有幫助