Quantcast
Channel: 神魂顛倒論壇-Flash--Front-end網頁前端討論最新50篇論壇主題-全文
Viewing all articles
Browse latest Browse all 735

JavaScript狀態列輪播跑馬燈

$
0
0
JavaScript狀態列輪播跑馬燈

請在<BODY>標籤中加入下列程式碼

以下為《HTML》原始碼
			


請將以下程式碼複製至您的<BODY>與</BODY>之間


以下為《JS》原始碼
<!-------JavaScript狀態列輪播跑馬燈 START--------> 
<script language="JavaScript">
<!--
var speed = 10
var pause = 2000
var timerID = null
var bannerRunning = false
var ar = new Array()
ar[0] = " 這是狀態列輪播跑馬燈示範"
ar[1] = " 使用方式如下:"
ar[2] = " 將以下程式碼複製至您的<body>與</body>之間即可"
ar[3] = " 在<body>標籤中加入下列程式碼"
var message = 0
var state = ""
clearState()
function stopBanner()
{
if (bannerRunning)
clearTimeout(timerID)
bannerRunning = false
}
function startBanner()
{
stopBanner()
showBanner()
}
function clearState()
{
state = ""
for (var i = 0; i < ar[message].length; ++i)
{
state += "0"
}
}
function showBanner()
{
if (getString())
{
message++
if (ar.length <= message)
message = 0
clearState()
timerID = setTimeout("showBanner()", pause)
bannerRunning = true
}
else
{
var str = ""
for (var j = 0; j < state.length; ++j)
{
str += (state.charAt(j) == "1") ? ar[message].charAt(j) : ""
}
window.status = str
timerID = setTimeout("showBanner()", speed)
bannerRunning = true
}
}
function getString()
{
var full = true
for (var j = 0; j < state.length; ++j)
{
if (state.charAt(j) == 0)
full = false
}
if (full)
return true
while (1)
{
var num = getRandom(ar[message].length)
if (state.charAt(num) == "0")
break
}
state = state.substring(0, num) + "1" + state.substring(num + 1, state.length)
return false
}
function getRandom(max)
{
return Math.round((max - 1) * Math.random())
}
// -->
</script>
<!-------JavaScript狀態列輪播跑馬燈 END-------->

Viewing all articles
Browse latest Browse all 735

Trending Articles