บทความนี้อธิบายถึงรหัสเอฟเฟกต์พิเศษสำหรับการใช้การบินเข้าสู่ดวงดาวโดย JS. และแบ่งปันกับคุณสำหรับการอ้างอิงของคุณ
รหัสการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <html>
<head>
<title> เอฟเฟกต์การบินความเร็วความเร็วของ Starry Sky </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 = "ตำแหน่ง: สัมบูรณ์; top: 0px; ซ้าย: 0px"> <div style = "ตำแหน่ง: ญาติ">');
สำหรับ (i = 0; i <xl; i ++) {
document.write ('<div id = "div" style = "ตำแหน่ง: Absolute; top: 0; ซ้าย: 0; Width: 5px; ความสูง: 5px;'+'font-size: 10px; color: #ffffff">. </div>');
-
document.write ('</div> </div>');
ชุดฟังก์ชัน () {
สำหรับ (i = 0; i <xl; i ++) {
โอน (i)
xf [i] = xw/14;
-
-
ฟังก์ชั่นกำหนด () {
sdiv.style.top = document.body.scrolltop;
สำหรับ (i = 0; i <xl; i ++) {
xf [i]-= xs [i]*25;
ถ้า (xf [i] <4) xf [i] = 3;
div [i] .style.top = xy [i];
div [i] .style.left = xx [i];
div [i] .style.fontsize = xf [i];
-
-
ฟังก์ชั่นบิน () {
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);
สำหรับ (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;
-
-
กำหนด();
settimeout ('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);
ถ้า (xr == 3) xb [i] =-xe;
ถ้า (xr == 2) xb [i] = xw+xe;
ถ้า (xr == 1) xa [i] =-xe;
ถ้า (xr == 0) xa [i] = xh;
-
ชุด();
บิน();
</script>
</body>
</html> </td>
</tr>
</table>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน