다음과 같은 문제가 있습니다. 누구의 생성자에서 두 개의 이미지를로드하는 클래스를 만들었고 완전히로드 될 때까지 나머지 초기화를 지연해야합니다. 놀랍게도JS 이벤트 핸들러가 다른 핸들러의 실행을 인터럽트 할 수 있습니까?
var self = this;
var imagesToLoad = 4;
var finishInit = function() {
alert(imagesToLoad);
imagesToLoad--;
if (imagesToLoad == 0) {
// remaining initializations
}
}
this._prevIcon = new Image();
this._prevIcon.onload = finishInit;
this._prevIcon.src = "img1.png";
this._nextIcon = new Image();
this._nextIcon.onload = finishInit;
this._nextIcon.src = "img2.png";
this._pauseIcon = new Image();
this._pauseIcon.onload = finishInit;
this._pauseIcon.src = "img3.png";
this._playIcon = new Image();
this._playIcon.onload = finishInit;
this._playIcon.src = "img4.png";
, 실행 표시 대화 상자가 파이어 폭스 7 4,3,2,4에 4,4,4,4를 읽어 : (생성자에서 발췌) 다음과 같이 내가 사용하는 코드는 IE 9에서 JS가 단일 스레드로 간주되어 한 이벤트 핸들러가 다른 스레드를 인터럽트해서는 안된다고 생각해서 혼란 스럽습니다. 캐치 (또는 실수)는 어디에 있습니까?
미리 감사드립니다. 감사합니다. Tomek
'src'와 'onload'행을 전환 해보십시오. – CamelCamelCamel