Re: [問題] javascript效果不能合併
以下是兩個效果合併一起的程式碼...
目前卡在模仿駭客任務文字下墜效果的部份可以動
但最底下的文字跑馬燈的效果就不行了
我有試過把<body>裡面的onload刪掉
但這樣狀況就顛倒過來了= = 變成駭客效果不能動 跑馬燈可以@@
我一直想不懂該用什麼方法讓兩者同時都能運作
希望板上前輩們可以指點一下 感謝!!!
<HTML>
<HEAD>
<TITLE>Test</TITLE>
<meta http-equiv="Content-Type" content="text/html;charset=big5">
<script type="text/javascript">
function $(id) {
return document.getElementById(id); //獲取控件的ID
}
function marquee(time, oDiv, oLtd, oRtd) //製作一個marquee類別
{
/*
time 值越大速度越慢
oDiv最外層div
oLtd左邊的td
oRtd右邊的td
*/
var timer, width = oLtd.offsetWidth;
function move() {
if (oDiv.scrollLeft >= width) //當捲動列移動到最後時,重新
開始
oDiv.scrollLeft = 0;
else
oDiv.scrollLeft ++; //一直捲動
}
oRtd.innerHTML = oLtd.innerHTML; //左側內容轉移動到右側
oDiv.style.overflow = "hidden"; //隱藏最外層div
oRtd.style.width = oLtd.offsetWidth; //右側td的寬度
oDiv.onmouseover = function () { //游標移動過來的事件
window.clearInterval(timer); //清空定時器-停止捲動
};
oDiv.onmouseout = function () {
timer = window.setInterval(move, time); //游標移走便開始捲動
};
timer = window.setInterval(move, time); //開始捲動
};
window.onload = function () {
new marquee(25, $("myDiv"), $("myTd1"), $("myTd2"));
}
</script>
</HEAD>
<script language="javascript">
var strCount;
var str;
var Color;
var Font;
var sLine =
"A<br>B<br>C<br>D<br>E<br>F<br>1<br>.<br>2<br>3<br>4<br>5<br>.<br>A<br>a<br>B<br>b<br>C<br>d";
function OnLoad()
{
strCount = 40;
str = [];
Color = [];
Font = [];
Color[0] = "#002211";//文字的顏色
Color[1] = "#003311";
Color[2] = "#005511";
Color[3] = "#008811";
Color[4] = "#00BB99";
Color[5] = "#114411";
Color[6] = "#335566";
Color[7] = "#668899";
Color[8] = "#99BBAA";
Color[9] = "#CECECC";
Font[0] = "10px"; //文字的大小
Font[1] = "12px";
Font[2] = "14px";
Font[3] = "16px";
Font[4] = "18px";
setTimeout("strik()",50);
}
function strik()
{
for(var i=0;i<strCount;i++)
{
if(typeof(str[i]) != "undefined") //如果字符串存在
{
if(str[i]["Carch"].style.pixelTop > heike.clientHeight)
{
str[i]["Carch"].outerHTML = "";
delete str[i]["Level"];//刪除陣列元素
delete str[i]["Speed"];
delete str[i]["Carch"];
delete str[i];
}
else
{
str[i]["Carch"].style.pixelTop += str[i]["Speed"];
}
}
else if(Math.random()<0.25) //隨機小數
{
str[i] = new Array();
str[i]["Level"] = Math.round(Math.random()*4);
str[i]["Speed"] = (Math.round(Math.random()*str[i]["Level"])<<2)+10;
document.all["heike"].insertAdjacentHTML("AfterBegin","<span
id='SPAN_"+i+"'>"+sLine+"</span>");
str[i]["Carch"] = document.all["SPAN_"+i];
str[i]["Carch"].style.fontSize = Font[str[i]["Level"]]; //字體
str[i]["Carch"].style.position = "absolute"; //位置
str[i]["Carch"].style.pixelLeft =
Math.round(Math.random()*heike.clientWidth); //x坐標
str[i]["Carch"].style.pixelTop = -str[i]["Carch"].offsetHeight; //y坐標
str[i]["Carch"].style.color = Color[str[i]["Level"]+5]; //顏
色
str[i]["Carch"].style.filter =
"glow(Color="+Color[str[i]["Level"]]+",Strength=5)";//濾鏡效果
str[i]["Carch"].style.zIndex = str[i]["Level"];
//z-Index
}
}
setTimeout("strik()",50);
}
</script>
<BODY onload="OnLoad()">
<div style="position:fixed;top:130px;height:500px;overflow:hidden;zIndex:0">
<table width="100%" height="80%" border="0" cellspacing="0" cellpadding="0">
<tr><td align="center" height="100%"><div id="heike"></div></td></tr>
</table></div>
<div id="myDiv" style="position:fixed;left:10px;bottom:6px;border:#CCCCCC 1px
dashed;width:1000px;overflow:hidden"><!--設置顯示的寬度-->
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td id="myTd1">
<table width="1048" cellpadding="0" cellspacing="0"><!--注意這裡的寬
度必須設置,並且要設置為具體值-->
<tr align="left">
<td><font color="green">OOOOOOOOOOOOOOOOOOO!
</font></td>
<td><font color="green">PPPPPPPPPPPPPPPPPPP!
</font></td>
<td><font color="green">QQQQQQQQQQQQQQQQQQQ!
</font></td>
<td><font color="green">RRRRRRRRRRRRRRRRRRR!
</font></td>
</tr>
</table>
</td>
<td id="myTd2"></td>
</tr>
</tbody>
</table>
</div>
</BODY>
</HTML>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.42.94.114
推
12/06 17:53, , 1F
12/06 17:53, 1F
→
12/06 17:54, , 2F
12/06 17:54, 2F
→
12/06 19:00, , 3F
12/06 19:00, 3F
→
12/06 19:01, , 4F
12/06 19:01, 4F
→
12/06 19:02, , 5F
12/06 19:02, 5F
→
12/06 19:04, , 6F
12/06 19:04, 6F
→
12/06 19:04, , 7F
12/06 19:04, 7F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 5 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章