この記事では、JSによって星に迷いを実装するための特殊効果コードについて説明し、参照のためにあなたと共有されています。
特定の実装コードは次のとおりです。
次のようにコードをコピーします:<html>
<head>
<title>星空のスピードスピードフライング効果</title>
<style type = "text/css">
<! -
体 {
バックグラウンドカラー:#000066;
}
- >
</style>
</head>
<body>
<スクリプト言語= "javascript">
XL = 8;
xh = xw = xr = xe = xmy = xmx = xwd = xhd = 0;
xf = new Array();
xy = new Array();
xx = new Array();
xs = new Array();
xa = new Array();
xb = new Array();
ini = new Array();
document.write( '<div id = "sdiv" style = "position:absolute; top:0px; left:0px"> <div style = "position:relative">');
for(i = 0; i <xl; i ++){
document.write( '<div id = "div" style = "position:absolute; top:0; left:0; width:5px; height:5px;'+'font-size:10px; color:#ffffff">。</div>');
}
document.write( '</div> </div>');
関数set(){
for(i = 0; i <xl; i ++){
転送(i)
xf [i] = xw/14;
}
}
function assign(){
sdiv.style.top = document.body.scrolltop;
for(i = 0; i <xl; i ++){
xf [i] - = xs [i]*25;
if(xf [i] <4)xf [i] = 3;
div [i] .style.top = xy [i];
div [i] .style.left = xx [i];
div [i] .style.fontsize = xf [i];
}
}
functionfly(){
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 <xl; 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] <xmx+xwd)&&(xy [i]> xmy-xhd)&&(xy [i] <xmy+xhd)){
転送(i)
}
if((xx [i] <0)||(xx [i]> xw)||(xy [i] <0)||(xy [i]> xh)){
xf [i] = xw/14;
}
}
割り当てる();
setimeout( 'fly()'、1);
}
関数転送(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;
}
セット();
飛ぶ();
</script>
</body>
</html> </td>
</tr>
</table>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています