网站加入flash广告代码,利用DIV层来控制进度的状态,如果加载swf文件到100%的时候就显示出flash,把AD层隐藏掉,请看下面实现方法。 先定义进度条显示层: <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>
<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); } }
|