First, define the progress bar display layer:
CopyCode The Code is as follows: <div> <SPAN class = "Intro"> download progress: </span>
<Div class = "barborder">
<Div class = "bar" id = "loadpercent"> </div>
</Div>
</Div>
Define the ad layer:Copy codeThe Code is as follows: <Div id = "showad"> </div>
Define the flash display layer:
<Div id = "showswf" class = "show" style = "display: none;">
<Object ID = "flashgame" ...... content omitted ......>
</Object>
</Div>
JS Code:Copy codeThe Code is as follows: <script language = "JavaScript">
If (window. Navigator. useragent. indexof ("Firefox")> = 1) // determines whether the browser is Firefox. Firefox does not support the percentloaded () function
{
Document. getelementbyid ("loadpercent"). innerhtml = "Firefox! No attentions ";
Document. getelementbyid ("showswf"). style. Display = 'block ';
}
Else
{
Refreshprogress ();
}
Function show () // hide the ad layer and display the flash Layer
{
Document. getelementbyid ("showad"). style. Display = 'none ';
Document. getelementbyid ("showswf"). style. Display = 'block ';
}
Function refreshprogress () // refresh progress bar Function
{
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 look at some flash game websites and how to control them.Source codeYou can learn more about the knowledge and skills.