커다란 배경 이미지가 포함 된 큰 페이지가 생성되므로 프리 로더를 표시하고 백그라운드에서 이미지를로드하고 로더를 업데이트하는 것이 가장 좋습니다 (이미지 4/20 , ecc). 내 문제는 : onload 이벤트가 발생하면 내 로더 diasppears하지만 여전히 이미지로드를 볼, 이것은 완전히로드되지 않은 것을 의미합니다. 왜 이런 일이 생길까요? 어떤 생각?image onload trouble
$(document).ready(function(){
// This will be executed when the DOM is ready.
});
$(window).load(function(){
// This will be executed when the whole document and all its
// referenced items (style sheets, scripts, images, etc.) are loaded.
});
그러나 :
nImages = $('.slide').length;
loadedImgs = 0;
var bgImages = ['img/bbb.png','img/bbb2.png','img/bbb3.png'];
$('.slide').each(function(i){
var curSlide = $(this);
var img = new Image();
img.src = bgImages[ i % 3 ];
img.onLoad = imageLoaded(img, curSlide);
})
function imageLoaded(img, curSlide){
curSlide.css('backgroundImage', 'url(' + img.src + ')');
loadedImgs++;
if(nImages == loadedImgs){
$('#container').css('visibility','visible');
$('#loader-cont').fadeOut(1000);
}
$('.loader-inner .title').text(loadedImgs/nImages);
}
대신에 onready를 사용하십시오. – NotGaeL
또한 패턴은 img.onload = someFunc입니다. _THEN_ img.src = someFile; 로드하기 전에 파일이로드 될 때 수행 할 작업을 지정해야합니다. 이미지가 이미 캐시 된 경우 쉽게 onload 이벤트가 발생하지 않을 수 있습니다. 그것은 (대부분) 작동 할 수도 있지만 올바른 접근 방식은 아닙니다. – enhzflep