煙火
將下列程式碼複製至<body>程式碼</body>之間。
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript"><!--wenchin var fireNo = 10; var fireSize = 200; var speed = 10; var wa = 10; var space = 10 var fireColor = new Array('#ffff00','#ff3300','#0000ff','#66ff66','#00ffff','#ff66ff','#ffcc00','#ff80ff','#ff0080'); var _dom=(document.all?3:(document.getElementById?1:(document.layers?2:0)));var fireLay=""; for (i=0; i<fireNo*wa; i++) { if (_dom == 1 || _dom == 3) { fireLay += '<DIV id="fire' + i + '" style="position:absolute; width:1px; height:1px left:0px; top=0px; font-size:1px; background:#FFFFFF;"></DIV>'; } if (_dom == 2) { fireLay += '<LAYER name="fire'+ i +'" left="0" top="0" clip="0,0,1,1" bgcolor="#FFFFFF"></LAYER>\n'; } } document.writeln(fireLay); function getWindowSize() {if(_dom == 1 || _dom == 2) { win_width = self.innerWidth; win_height = self.innerHeight; } if (_dom == 3) { win_width = document.body.clientWidth; win_height = document.body.clientHeight; } } function getScrollPosY() {if (_dom == 1) return scrollY; if (_dom == 2) return pageYOffset; if (_dom == 3) return document.body.scrollTop; } function showLayer(layerName){if (_dom == 1) document.getElementById(layerName).style.visibility = "visible"; if (_dom == 2) document.layers[layerName].visibility = "show"; if (_dom == 3) document.all(layerName).style.visibility = "visible"; } function hideLayer(layerName){if (_dom == 1) document.getElementById(layerName).style.visibility = "hidden"; if (_dom == 2) document.layers[layerName].visibility = "hide"; if (_dom == 3) document.all(layerName).style.visibility = "hidden"; } function hanabi() {for (i=0; i<fireNo*wa; i++) { if (_dom == 1) var div = document.getElementById("fire" + i).style; if (_dom == 2) var div = document.layers["fire" + i]; if (_dom == 3) var div = document.all("fire" + i).style; zure1 = Math.floor(i/fireNo)%2 == 0 ? 0:(Math.PI / fireNo); zure2 = Math.floor(i/fireNo) * space; ran = (radius1>(fireSize*0.8)) ? Math.floor(Math.random()*20-10) : 0; radius2 = (radius1 - zure2) > 0 ? radius1 - zure2 : 0; if ((radius1 - zure2) > fireSize) { hideLayer("fire" + i); } else { showLayer("fire" + i); } div.left = centerX + Math.cos(i * (Math.PI * 2 / fireNo) + zure1) * (radius2) + ran; div.top = centerY + Math.sin(i * (Math.PI * 2 / fireNo) + zure1) * (radius2) + ran; if (radius2 < fireSize * 0.4) { if (_dom == 1 || _dom == 3) { div.background = startColor; div.width = 1; div.height = 1; } if (_dom == 2){ div.bgColor = startColor; div.clip.width = 1; div.clip.height = 1; } } else if (radius2 < fireSize * 0.8) { if (_dom == 1 || _dom == 3) { div.width = 2; div.height = 2; } if (_dom == 2){ div.clip.width = 2; div.clip.height = 2; } } else { if (_dom == 1 || _dom == 3) { div.background = fireColor[Math.floor(Math.random() * fireColor.length)]; div.width = Math.floor(Math.random()*2+1); div.height = Math.floor(Math.random()*2+1); } if (_dom == 2){ div.bgColor = fireColor[Math.floor(Math.random() * fireColor.length)]; div.clip.width = Math.floor(Math.random()*2+1); div.clip.height = Math.floor(Math.random()*2+1); } } } radius1 += speed; if (radius1 > (fireSize + space * wa)) { setHanabiPos(); } else { setTimeout("hanabi()",10);} } function setHanabiPos() {rev = 0; radius1 = 0; getWindowSize(); sclY = getScrollPosY(); startColor = fireColor[Math.floor(Math.random() * fireColor.length)]; centerX = Math.floor(Math.random() * (win_width - (fireSize + space * wa) * 2) + (fireSize + space * wa)); centerY = Math.floor(Math.random() * (win_height - (fireSize + space * wa) * 2) + (fireSize + space * wa)) + sclY; setTimeout("hanabi()",500); } setHanabiPos(); //wenchin --></SCRIPT> |