/** * Created by jljsj on 15/6/3. */ $(function() { $.ajaxSetup({ cache: true }); var loadData = [ "https://os.alipayobjects.com/rmsportal/PfhNcINWBAnMIWR.js", // easeljs-0.8.0.min.js "https://os.alipayobjects.com/rmsportal/nGFyCGHAblMWsYE.js", // 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 = $("
" + t + "
") } self.load() }, load: function() { var self = this, num = 0; function endLoad() { self.loadBox.addClass("load-out").one(animEndStr, function() { self.loadBox.remove(); bannerAnim.init(); }); } function getLoad() { var str = loadData[num]; if (str.indexOf(".js") >= 0) { $.getScript(str.indexOf('http') === 0 ? str : (rootUrl + str), function() { num++; self.loadBar.css("width", num / loadData.length * 100 + "%"); if (num >= loadData.length) { setTimeout(endLoad, 300); } else { getLoad(); } }) } else { var img = new Image(); img.onload = img.onerror = function() { num++; self.loadBar.css("width", num / loadData.length * 100 + "%"); if (num >= loadData.length) { setTimeout(endLoad, 300); } else { getLoad(); } }; img.src = str; } } getLoad(); } }; $().ready(function() { loadFunc.init() }); });