First define the progress bar display layer:
Copy Code code as follows:
<div><span class= "Intro" > Download Progress:</span>
<div class= "Barborder" >
<div class= "Bar" id= "Loadpercent" ></div>
</div>
</div>
Define AD layer:
Copy Code code as follows:
<div id= "Showad" ></div>
Define Flash Display layer:
<div id= "showswf" class= "show" style= "Display:none;" >
<object id= "FlashGame" ... Omit content ......>
</object>
</div>
JS Code:
Copy Code code as follows:
<script language= "JavaScript" >
if (Window.navigator.userAgent.indexOf ("Firefox") >=1)/To determine whether it is a Firefox browser, Firefox does not support percentloaded () function
{
document.getElementById ("Loadpercent"). Innerhtml= "firefox! No attentions ";
document.getElementById ("showswf"). style.display= ' block ';
}
Else
{
Refreshprogress ();
}
function Show ()//Hide ad layer, display flash layer
{
document.getElementById ("Showad"). style.display= ' None ';
document.getElementById ("showswf"). style.display= ' block ';
}
function refreshprogress ()//Refresh progress bar functions
{
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);
}
}
In fact, the best code is to see some flash game site, is how to control, look at the source code can understand more knowledge and skills.