有没有办法在Javascript或JQuery中为swfs制作预加载器

时间:2012-04-01 20:46:29

标签: javascript jquery preloader

有没有办法在Javascript或JQuery中制作预加载器,以便网页中的所有元素(如swfs和图像)在播放和显示之前完全加载。我在swfs的闪光灯中有一个预加载器,但有时它会起伏不定。我的代码工作正常,但它是一种在网页播放或使用网站显示元素之前使用Javascript或JQuery预加载整个页面的方法吗?

<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>

1 个答案:

答案 0 :(得分:1)

如果闪光灯部件是您的,可以这样做。这意味着从AS使用外部接口并调用JavaScript函数来判断加载了多少,并询问何时开始播放,但这是一种非宗教的方式。