Created
October 28, 2012 14:07
-
-
Save milushov/3968694 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.load = function(callback, act) { | |
if(act || __images.length === 0) callback.call(); | |
var cover = document.createElement('div'), | |
counter = 0; | |
cover.id = 'cover'; | |
cover.style.width = wwh()[0]+'px'; | |
cover.style.height = wwh()[1]+'px'; | |
cover.innerHTML = ' \ | |
<span>Загружено изображений:</span> \ | |
<span id="load_percent">0%</span>'; | |
$('body').appendChild(cover); | |
var load_percent = $('#load_percent'); | |
images = new Object(); | |
for (var i = 0; i < __images.length; i++) { | |
var key = __images[i].split('/').last(); | |
images[key] = new Image(); | |
images[key].onload = function() { | |
counter ++; | |
if(counter % 3 === 0) { | |
load_percent.innerHTML = (parseFloat((counter/__images.length).toFixed(2)) * 100).toFixed() + '%'; | |
console.log(new Date().getMilliseconds()); | |
} | |
if(counter === __images.length - 1) { | |
//$('body').removeChild(cover); | |
callback.call(); | |
} | |
} | |
images[key].src = __images[i]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this approach sucks