0
img 수를 계산하려고하지만 작동하지 않습니다. div도 계산하려고했으나 너무 효과가 없었습니다. 항상 0을 반환합니다.jQuery는 길이와 각각을 사용할 수 없습니다.
progressBar = {
countElmt: 0,
loadedElmt: 0,
init: function() {
console.log('init dedans 1');
var that = this;
this.countElmt = $('img').length;
// Construction et ajout progress bar
var $progressBarContainer = $('<div/>').attr('id', 'progress-bar-container');
$progressBarContainer.append($('<div/>').attr('id', 'progress-bar'));
$progressBarContainer.appendTo($('body'));
// Ajout container d'éléments
var $container = $('<div/>').attr('id', 'progress-bar-elements');
$container.appendTo($('body'));
// Parcours des éléments à prendre en compte pour le chargement
$('img').each(function() {
console.log('each ok');
$('<img/>') .attr('src', $(this).attr('src'))
.on('load error', function() {
that.loadedElmt++;
that.updateProgressBar();
})
.appendTo($container);
});
console.log('fin each, nombre d images = ' + progressBar.countElmt);
},
updateProgressBar: function() {
$('#progress-bar').stop().animate({
'width': (progressBar.loadedElmt/progressBar.countElmt) * 100 + '%'
});
}
};
console.log('init avant');
progressBar.init();
누군가가 문제의 출처를 알 수 있습니까?
$ ('img'). 길이 = 0? –
돔이 준비되어 있는지 확인 하시겠습니까? – KingKongFrog