close
煙火背景(一)
語法說明:
- 在 var fireNo = 5; 中修改煙火的樣式
- 在 var fireSize = 80; 中修改煙火的大小
- 在 var speed = 5; 中修改煙火的展開速度
- 在 var wa = 6; 中修改特效總使用時間
- 在 var fireColor = new Array('#ffffff','#ff0000','#00ff00','#ffff00','#00ffff','#ff00ff','#ff8000','#ff80ff','#ff0080'); 中修改煙火的顏色
- 在 setTimeout("hanabi()",2000); 中修改煙火之間間隔的時間(每1秒=1000)
<!--煙火背景_開始--> <script language="JavaScript"> <!-- <!--在此修改煙火的樣式--> var fireNo = 5; <!--在此修改煙火的大小--> var fireSize = 80; <!--在此修改煙火的展開速度--> var speed = 5; <!--在此修改特效總使用時間--> var wa = 6; var space = 15 var fireColor = new Array('#ffffff','#ff0000','#00ff00','#ffff00','#00ffff','#ff00ff','#ff8000','#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; <!--在此修改煙火之間間隔的時間(每1秒=1000)--> setTimeout("hanabi()",2000); } setHanabiPos(); --> </script> <!--煙火背景_結束--> |
全站熱搜