有沒有辦法在JavaScript或JQuery中製作預加載器,以便像swfs和圖片這樣的網頁中的所有元素在播放和顯示之前都可以完全加載。我在swf的flash中有一個預加載器,但有時候它會起伏不定。我的代碼可以正常工作,但它是在網頁播放或使用網站顯示元素之前使用Javascript或JQuery預加載整個頁面的一種方式嗎?有沒有辦法在Javascript或JQuery中爲swfs製作預加載器
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>???</title>
<script type="text/javascript" src="swfobject-1.5.js"></script>
<script language="javascript" type="text/javascript" src="jquery-1.2.6.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
if(readCookie("flashPlayed") == "true"){
Jvid()&&Bg()
}
});
function launchFlash(){
if(readCookie("flashPlayed") != "true"){
var homeflash = new SWFObject("???.swf", "BG", "100%", "100%", "8");
homeflash.addParam("wmode","transparent");
homeflash.write("videoBg");
var homeflash = "Bg";
setTimeout("Bg()");
setTimeout("Jvid()",5000);
setTimeout("removeFlash()",5000);
}
}
function readCookie(cookieName){
var searchName = cookieName + "="
var cookies = document.cookie
var start = cookies.indexOf(cookieName)
if (start == -1){ // cookie not found
return ""
}
start += searchName.length //start of the cookie data
var end = cookies.indexOf(";", start)
if (end == -1){
end = cookies.length
}
return cookies.substring(start, end)
}
function Jvid(){
$("#videos").hide();
}
function Bg(){
$("#test").css({"background":'url("???.jpg")',"background-position":'top center'});
}
function removeFlash(){
$("#videoBg").empty();
$("#videoBg").animate({ top:"-9999px"}, 1);
window.location.assign("http://???.com")
}
</script>
<style>
#test {
font-family: Geneva,Arial,Helvetica,sans-serif;
font-size: 12px;
height: 100%;
margin: 0;
padding: 0;
text-align: left;
width: 100%;
position:relative;
background:url(???.jpg) top center repeat #000;
}
#videoBg{
position:fixed;
top:-5px;
left:0px;
height:100%;
width:100%;
}
#videos{margin:0 auto 0;
padding:0;
height:301px;
width:205px;
position:absolute;
/*border-style:solid;
border-color:red;*/
top:134px;
left:800px;
*left:645px;
left:645px\0/;
}
</style>
</head>
<body id="test">
<div id="videos">
<script src="swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
var flashvars = {};
var params = {};
params.wmode = "transparent";
swfobject.embedSWF("???.swf", "videos", "205", "301", "8.0.0", '', flashvars, params);
</script>
</div>
<div id="videoBg"></div>
<script type="text/javascript">
setTimeout("launchFlash()", 7000);
</script>
</body>
嘗試更新你的閃存(新版本提供了改進,但已經資源已經存在,謹防),在其他瀏覽器上測試。 preloaders不會導致choppiness(什麼讓你這麼說?) – Joseph 2012-04-01 21:51:49
@Joseph如果你的頁面充滿了JavaScript處理程序,並且你通過ajax加載一個新的swf,swf的preloader有時會導致choppiness,但它可以通過調用部分你的JS函數使用'setTimeout(func,0)',這將使線程更好地完成他的工作,並播放預加載器。 – khael 2012-04-02 04:20:40