2015-06-04 16:16:07 +08:00
|
|
|
/**
|
|
|
|
* Created by jljsj on 15/6/3.
|
|
|
|
*/
|
|
|
|
$(function () {
|
|
|
|
var loadData = ["/static/easeljs-0.8.0.min.js", "/static/TweenMax.min.js", "/static/home.js", "https://t.alipayobjects.com/images/T1CFtgXb0jXXXXXXXX.jpg"];
|
|
|
|
var animEndStr = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
|
|
|
|
var loadFunc={
|
|
|
|
init:function(){
|
|
|
|
var self=this;
|
|
|
|
self.body=$("body");
|
|
|
|
self.header=$("#header")||$("header");
|
|
|
|
self.main=$(".main");
|
|
|
|
self.footer=$("#footer")||$("footer");
|
|
|
|
self.addLoad()
|
|
|
|
},
|
|
|
|
addLoad:function (){
|
|
|
|
var self=this;
|
|
|
|
self.loadBox=$("<div class='load-main-box'>" +
|
|
|
|
"<div class='load-box'>" +
|
|
|
|
"<em><img src='https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg' width='50' height='50'></em>" +
|
|
|
|
"<span>Ant Design</span>" +
|
|
|
|
"</div>" +
|
|
|
|
"<div class='load-bar'></div>" +
|
2015-06-10 14:20:26 +08:00
|
|
|
"</div>").appendTo(".banner-box");
|
2015-06-04 16:16:07 +08:00
|
|
|
self.loadBar=self.loadBox.find(".load-bar");
|
|
|
|
var loadText=self.loadBox.find("span"),
|
|
|
|
str=loadText.text(),
|
|
|
|
loadClass=["yoyo-load0","yoyo-load1","yoyo-load2","yoyo-load3","yoyo-load4","yoyo-load5"];
|
|
|
|
loadText.empty();
|
|
|
|
function c_random(num,arrlen){
|
|
|
|
var arr=[];
|
|
|
|
function r(i){
|
|
|
|
var t=Math.round(Math.random()*(num-1));
|
|
|
|
if(t==arr[i-1]){
|
|
|
|
r(i);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
arr.push(t)
|
|
|
|
}
|
|
|
|
for(var i=0;i<arrlen;i++){
|
|
|
|
r(i)
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
var tarr=c_random(loadClass.length,str.length);
|
|
|
|
for(var i=0;i<str.length;i++){
|
|
|
|
var t=str[i];
|
|
|
|
if(t==" "){
|
|
|
|
t=" "
|
|
|
|
}
|
|
|
|
var _class="yoyo-x-left";
|
|
|
|
if(i>0&&i<str.length-1){
|
|
|
|
_class=loadClass[tarr[i]]
|
|
|
|
}
|
|
|
|
if(i==str.length-1){
|
|
|
|
_class='yoyo-x-right'
|
|
|
|
}
|
|
|
|
loadText.append("<p class='"+_class+"'>"+t+"</p>")
|
|
|
|
}
|
|
|
|
self.load()
|
|
|
|
},
|
|
|
|
load:function (){
|
2015-06-09 14:04:49 +08:00
|
|
|
var self=this,num= 0;
|
|
|
|
function endLoad(){
|
|
|
|
self.loadBox.addClass("load-out").one(animEndStr, function () {
|
|
|
|
self.loadBox.remove();
|
|
|
|
bannerAnim.init();
|
|
|
|
});
|
2015-06-04 16:16:07 +08:00
|
|
|
}
|
2015-06-09 14:04:49 +08:00
|
|
|
function getLoad(){
|
|
|
|
var str=loadData[num];
|
|
|
|
if(str.indexOf(".js")>=0){
|
2015-09-17 18:05:06 +08:00
|
|
|
$.getScript(rootUrl + str,function (){
|
2015-06-09 14:04:49 +08:00
|
|
|
num++;
|
|
|
|
self.loadBar.css("width",num/loadData.length*100+"%");
|
|
|
|
if(num>=loadData.length){
|
|
|
|
setTimeout(endLoad,300);
|
|
|
|
}else{
|
|
|
|
getLoad();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-06-04 16:16:07 +08:00
|
|
|
}else{
|
|
|
|
var img = new Image();
|
|
|
|
img.onload = img.onerror = function () {
|
|
|
|
num++;
|
2015-06-09 14:04:49 +08:00
|
|
|
self.loadBar.css("width",num/loadData.length*100+"%");
|
2015-06-04 16:16:07 +08:00
|
|
|
if (num >= loadData.length) {
|
2015-06-09 14:04:49 +08:00
|
|
|
setTimeout(endLoad,300);
|
|
|
|
}else{
|
|
|
|
getLoad();
|
2015-06-04 16:16:07 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
img.src = str;
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 14:04:49 +08:00
|
|
|
getLoad();
|
2015-06-04 16:16:07 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
$().ready(function (){
|
|
|
|
loadFunc.init()
|
|
|
|
});
|
|
|
|
|
2015-06-04 18:15:06 +08:00
|
|
|
});
|