AGAMES 討論區

 找回密碼
 快速註冊
搜索
查看: 1502|回復: 1
打印 上一主題 下一主題

背景流星 [複製鏈接]

七級帝王會員

☆Prince★}+}|電腦王子

Rank: 7Rank: 7Rank: 7

帖子
3799
EXP
6040 點
金幣
4990 個
好友
0
註冊時間
2008-3-27

友誼之星勳章

跳轉到指定樓層
樓主
發表於 2008-11-7 18:01:48 |只看該作者 |倒序瀏覽
語法中最頂,已註明可修改的部份
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!-- Beginning
  3. var dl = 15;  // 流星之間距離
  4. var size = 5; // 流星大小
  5. var fontcolor = "red"; // 流星顏色
  6. var yourstar = "★"; // 流星形狀 可用其它圖案或文字代替
  7. var meteorNo = 5; // 流星移動速度 數字越大越慢
  8. var sizeStep = 2; // 流星移動角度
  9. var move = true;
  10. var meteorRate = 100; // 每次出現流星時間 數字越大越慢
  11. var useImg = 0;
  12. starname=(document.all?3:(document.getElementById?1:(document.layers?2:0)));
  13. function getWindowSize() {
  14. if(starname == 1 || starname == 2) {
  15. win_width = self.innerWidth;
  16. win_height = self.innerHeight;
  17. }
  18. if (starname == 3) {
  19. win_width = document.body.clientWidth;
  20. win_height = document.body.clientHeight;
  21. }
  22. }
  23. function getScrollPosX() {
  24. if (starname == 1) return scrollX;
  25. if (starname == 2) return pageXOffset;
  26. if (starname == 3) return document.body.scrollLeft
  27. }
  28. function getScrollPosY() {
  29. if (starname == 1) return scrollY;
  30. if (starname == 2) return pageYOffset;
  31. if (starname == 3) return document.body.scrollTop;
  32. }
  33. function showLayer(layerName){
  34. if (starname == 1) document.getElementById(layerName).style.visibility = "visible";
  35. if (starname == 2) document.layers[layerName].visibility = "show";
  36. if (starname == 3) document.all(layerName).style.visibility = "visible";
  37. }
  38. function hideLayer(layerName){
  39. if (starname == 1) document.getElementById(layerName).style.visibility = "hidden";
  40. if (starname == 2) document.layers[layerName].visibility = "hide";
  41. if (starname == 3) document.all(layerName).style.visibility = "hidden";
  42. }
  43. function moveLayerTo(layerName, x, y){
  44. if (starname == 1) {
  45. document.getElementById(layerName).style.left = x;
  46. document.getElementById(layerName).style.top = y;
  47. }
  48. if (starname == 2) {
  49. document.layers[layerName].left = x;
  50. document.layers[layerName].top = y;
  51. }
  52. if (starname == 3) {
  53. document.all(layerName).style.pixelLeft = x;
  54. document.all(layerName).style.pixelTop = y;
  55. }
  56. }
  57. var sx = new Array(), sy = new Array(), sclW = 0, sclH = 0;
  58. function initMeteor() {
  59. if (starname && meteorFlag == 0) {
  60. var ran = Math.random()*meteorRate;
  61. if (ran < 10) {
  62. getWindowSize();
  63. if (move) sclW = getScrollPosX(), sclH = getScrollPosY();
  64. sX = Math.floor(Math.random()*(win_width-meteorMaxSize-5)) + sclW;
  65. sY = Math.floor(Math.random()*(win_height-meteorMaxSize-5)) + sclH;
  66. eX = Math.floor(Math.random()*(win_width-meteorMaxSize-5)) + sclW;
  67. eY = Math.floor(Math.random()*(win_height-meteorMaxSize-5)) + sclH;
  68. for (var m=0; m<meteorNo; m++) {
  69. moveLayerTo("meteor"+m, sX, sY);
  70. sx[m] = sX; sy[m] = sY;
  71. }
  72. moveMeteor();
  73. }
  74. }
  75. setTimeout("initMeteor()", 100);
  76. }
  77. var meteorFlag = 0;
  78. function moveMeteor() {
  79. var l, xp, yp, stopflag = false;
  80. for (var m=0; m<meteorNo; m++) {
  81. if (meteorFlag >= m) {
  82. l = Math.abs(Math.sqrt(Math.pow((eX - sx[m]),2) + Math.pow((eY - sy[m]),2)));
  83. if (l > dl) {
  84. xp = dl / l * (eX - sx[m]) + sx[m];
  85. if (eX - sx[m] == 0) {
  86. if (sy[m] < eY) yp = sy[m] + dl;
  87. else yp = sy[m] - dl;
  88. } else yp = (sy[m] - eY) / (sx[m] - eX) * xp + sy[m] - (sy[m] - eY) / (sx[m] - eX) * sx[m];
  89. sx[m] = xp; sy[m] = yp;
  90. showLayer("meteor"+m);
  91. moveLayerTo("meteor"+m, sx[m], sy[m]);
  92. } else {
  93. hideLayer("meteor"+m);
  94. if (m == meteorNo-1) stopflag = true;
  95. }
  96. }
  97. }
  98. if (!stopflag) { meteorFlag += 1; tim = setTimeout("moveMeteor()", 10); }
  99. else { clearTimeout(tim); meteorFlag = 0; }
  100. }
  101. // End -->
  102. </script>
  103. <SCRIPT LANGUAGE="JavaScript">
  104. <!-- Beginning
  105. var starLay = '<SPAN id="gs" style="position:absolute; visibility:hidden;"></SPAN>';
  106. for (i= meteorNo-1; i>=0; i--)
  107. {size += sizeStep; meteorMaxSize = size;
  108. if (starname == 1 || starname == 3) {
  109. if (useImg == 0) starLay += '<SPAN id="meteor' + i +
  110. '" style="position:absolute; width:' + size + 'px; font-size:' + size +
  111. 'px; color:' + fontcolor + '; z-index:8; visibility:hidden;">' + yourstar + '</SPAN>';
  112. }
  113. if (starname == 2) {
  114. if (size == 1) size = 2;
  115. if (useImg == 0) starLay += '<LAYER name="meteor'+ i +
  116. '" z-index="10" visibility="hide"><FONT color="' + fontcolor + '" style="font-size:'
  117. + size + 'px;">' + yourstar + '</FONT></LAYER>';
  118. }
  119. }
  120. document.writeln(starLay);
  121. initMeteor();
  122. // End -->
  123. </SCRIPT>
複製代碼
Alta Multimedia - OnlineGames:http://www.alta.hk

Rank: 1

帖子
1
EXP
2 點
金幣
0 個
好友
0
註冊時間
2008-11-7
2
發表於 2008-11-7 19:32:37 |只看該作者
哇好令ar  我加左lu
您需要登錄後才可以回帖 登錄 | 快速註冊

Archiver|手機版|AGAMES 討論區

GMT+8, 2024-11-10 13:19 , Processed in 0.045465 second(s), 10 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回頂部