AGAMES 討論區
標題:
背景流星
[打印本頁]
作者:
dlalden
時間:
2008-11-7 18:01:48
標題:
背景流星
語法中最頂,已註明可修改的部份
<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning
var dl = 15; // 流星之間距離
var size = 5; // 流星大小
var fontcolor = "red"; // 流星顏色
var yourstar = "★"; // 流星形狀 可用其它圖案或文字代替
var meteorNo = 5; // 流星移動速度 數字越大越慢
var sizeStep = 2; // 流星移動角度
var move = true;
var meteorRate = 100; // 每次出現流星時間 數字越大越慢
var useImg = 0;
starname=(document.all?3:(document.getElementById?1:(document.layers?2:0)));
function getWindowSize() {
if(starname == 1 || starname == 2) {
win_width = self.innerWidth;
win_height = self.innerHeight;
}
if (starname == 3) {
win_width = document.body.clientWidth;
win_height = document.body.clientHeight;
}
}
function getScrollPosX() {
if (starname == 1) return scrollX;
if (starname == 2) return pageXOffset;
if (starname == 3) return document.body.scrollLeft
}
function getScrollPosY() {
if (starname == 1) return scrollY;
if (starname == 2) return pageYOffset;
if (starname == 3) return document.body.scrollTop;
}
function showLayer(layerName){
if (starname == 1) document.getElementById(layerName).style.visibility = "visible";
if (starname == 2) document.layers[layerName].visibility = "show";
if (starname == 3) document.all(layerName).style.visibility = "visible";
}
function hideLayer(layerName){
if (starname == 1) document.getElementById(layerName).style.visibility = "hidden";
if (starname == 2) document.layers[layerName].visibility = "hide";
if (starname == 3) document.all(layerName).style.visibility = "hidden";
}
function moveLayerTo(layerName, x, y){
if (starname == 1) {
document.getElementById(layerName).style.left = x;
document.getElementById(layerName).style.top = y;
}
if (starname == 2) {
document.layers[layerName].left = x;
document.layers[layerName].top = y;
}
if (starname == 3) {
document.all(layerName).style.pixelLeft = x;
document.all(layerName).style.pixelTop = y;
}
}
var sx = new Array(), sy = new Array(), sclW = 0, sclH = 0;
function initMeteor() {
if (starname && meteorFlag == 0) {
var ran = Math.random()*meteorRate;
if (ran < 10) {
getWindowSize();
if (move) sclW = getScrollPosX(), sclH = getScrollPosY();
sX = Math.floor(Math.random()*(win_width-meteorMaxSize-5)) + sclW;
sY = Math.floor(Math.random()*(win_height-meteorMaxSize-5)) + sclH;
eX = Math.floor(Math.random()*(win_width-meteorMaxSize-5)) + sclW;
eY = Math.floor(Math.random()*(win_height-meteorMaxSize-5)) + sclH;
for (var m=0; m<meteorNo; m++) {
moveLayerTo("meteor"+m, sX, sY);
sx[m] = sX; sy[m] = sY;
}
moveMeteor();
}
}
setTimeout("initMeteor()", 100);
}
var meteorFlag = 0;
function moveMeteor() {
var l, xp, yp, stopflag = false;
for (var m=0; m<meteorNo; m++) {
if (meteorFlag >= m) {
l = Math.abs(Math.sqrt(Math.pow((eX - sx[m]),2) + Math.pow((eY - sy[m]),2)));
if (l > dl) {
xp = dl / l * (eX - sx[m]) + sx[m];
if (eX - sx[m] == 0) {
if (sy[m] < eY) yp = sy[m] + dl;
else yp = sy[m] - dl;
} else yp = (sy[m] - eY) / (sx[m] - eX) * xp + sy[m] - (sy[m] - eY) / (sx[m] - eX) * sx[m];
sx[m] = xp; sy[m] = yp;
showLayer("meteor"+m);
moveLayerTo("meteor"+m, sx[m], sy[m]);
} else {
hideLayer("meteor"+m);
if (m == meteorNo-1) stopflag = true;
}
}
}
if (!stopflag) { meteorFlag += 1; tim = setTimeout("moveMeteor()", 10); }
else { clearTimeout(tim); meteorFlag = 0; }
}
// End -->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning
var starLay = '<SPAN id="gs" style="position:absolute; visibility:hidden;"></SPAN>';
for (i= meteorNo-1; i>=0; i--)
{size += sizeStep; meteorMaxSize = size;
if (starname == 1 || starname == 3) {
if (useImg == 0) starLay += '<SPAN id="meteor' + i +
'" style="position:absolute; width:' + size + 'px; font-size:' + size +
'px; color:' + fontcolor + '; z-index:8; visibility:hidden;">' + yourstar + '</SPAN>';
}
if (starname == 2) {
if (size == 1) size = 2;
if (useImg == 0) starLay += '<LAYER name="meteor'+ i +
'" z-index="10" visibility="hide"><FONT color="' + fontcolor + '" style="font-size:'
+ size + 'px;">' + yourstar + '</FONT></LAYER>';
}
}
document.writeln(starLay);
initMeteor();
// End -->
</SCRIPT>
複製代碼
作者:
moom8787
時間:
2008-11-7 19:32:37
哇好令ar 我加左lu
歡迎光臨 AGAMES 討論區 (http://forum.agames.hk/)
Powered by Discuz! X2