Skip to content

Instantly share code, notes, and snippets.

@milushov
Created October 28, 2012 14:07
Show Gist options
  • Save milushov/3968694 to your computer and use it in GitHub Desktop.
Save milushov/3968694 to your computer and use it in GitHub Desktop.
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];
}
};
@milushov
Copy link
Author

this approach sucks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment