先定義進度條顯示層:
複製代碼 代碼如下:<div><span class="intro">下載進度:</span>
<div class="barborder">
<div class="bar" id="loadpercent"></div>
</div>
</div>
定義廣告層: 複製代碼 代碼如下:<div id="showAD"></div>
定義FLASH顯示層:
<div id="showSWF" class="show" style="display:none;">
<object id="flashgame" ......省略內容......>
</object>
</div>
js代碼:複製代碼 代碼如下:<script language="javascript">
if(window.navigator.userAgent.indexOf("Firefox")>=1)//判斷是否為FIREFOX瀏覽器,FIREFOX不支援PercentLoaded()函數
{
document.getElementById("loadpercent").innerHTML= "Firefox!No Attentions";
document.getElementById("showSWF").style.display='block';
}
else
{
refreshProgress();
}
function show()//隱藏AD層、顯示FLASH層
{
document.getElementById("showAD").style.display='none';
document.getElementById("showSWF").style.display='block';
}
function refreshProgress()//重新整理進度條函數
{
var downProgressWidth=502;
var bar = document.getElementById("loadpercent");
var movie = document.getElementById("flashgame");
var nPercentLoaded = Math.abs(movie.PercentLoaded());
bar.style.width=Math.ceil(downProgressWidth*nPercentLoaded/100) +"px";
bar.innerHTML= nPercentLoaded +"%";
if(nPercentLoaded==100)
{
bar.style.width=(downProgressWidth-2) + "px"; bar.innerHTML= "Game download is complete"; show();
}
else
{
setTimeout('refreshProgress()',0);
}
}
其實最好的代碼,就是看一些flash遊戲網站,是怎樣控制,看下原始碼就可以瞭解更多的知識與技巧。