Cet article décrit le code d'effet spécial pour implémenter le vol dans les étoiles par JS., Et est partagé avec vous pour votre référence.
Le code d'implémentation spécifique est le suivant:
Copiez le code comme suit: <html>
<adal>
<Title> Effet de vol à vitesse de vitesse du ciel étoilé </TITAL>
<style type = "text / css">
<! -
corps {
Color en arrière-plan: # 000066;
}
->
</ style>
</ head>
<body>
<script linguisse = "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: absolu; top: 0px; gauche: 0px"> <div style = "position: relative">');
pour (i = 0; i <xl; i ++) {
Document.Write ('<div id = "div" style = "Position: Absolute; top: 0; gauche: 0; largeur: 5px; hauteur: 5px;' + 'Font-Size: 10px; couleur: #ffffff">. </div>');
}
document.write ('</div> </div>');
fonction set () {
pour (i = 0; i <xl; i ++) {
transfert (i)
xf [i] = xw / 14;
}
}
fonction attribute () {
sdiv.style.top = document.body.scrolltop;
pour (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];
}
}
fonction 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);
pour (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)) {
transfert (i)
}
if ((xx [i] <0) || (xx [i]> xw) || (xy [i] <0) || (xy [i]> xh)) {
xf [i] = xw / 14;
}
}
Attribuer();
setTimeout ('fly ()', 1);
}
transfert de fonction (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;
}
Ensemble();
voler();
</cript>
</docy>
</html> </td>
</tr>
</ table>
J'espère que cet article sera utile à la programmation JavaScript de tous