객체를 선택하고 객체를 지정하고 페이드 인하는 루프가 있지만 루프가 실행될 때 객체 ID는 마지막 항목에 남아 있습니다.
var ordered = Array(elements.length);
var x = 0;
$('#' + that.options.slide_name + '_' + that.nextslide).children().each(function () {
ordered[x] = $(this);
$(this).fadeOut(1);
$(this).attr('id','current_slide_content_' + x);
x++;
});
//fade each element
var time = that.options.fade_speed / ordered.length
var overlap = time / that.options.fade_step;
//time = time + overlap;
var wait = 0;
var num = 0;
var i = null;
var funcs = Array(ordered.length);
for(var a = 0; a < ordered.length; a++){
var w = wait;
var id = $('#current_slide_content_' + a);
window.setTimeout( function (event) {
id.fadeIn(time);
console.log(id);
},w);
//$('#current_slide_content_' + a).fadeIn(time); <-- on its own works, error is with the wait time
wait = time + wait;
}
실제로 타임 아웃 기능을 추가하는 최종 루프에 있도록 오류를 좁혔습니다.
for(var a = 0; a < ordered.length; a++){
var w = wait;
var id = $('#current_slide_content_' + a);
window.setTimeout( function (event) {
id.fadeIn(time);
console.log(id);
},w);
//$('#current_slide_content_' + a).fadeIn(time); <-- on its own works, error is with the wait time
wait = time + wait;
}
요소의 ID가 기록되면 다음과 같아야합니다.
foo_0 foo_1 foo_2
그러나 대신 다음과 같이 표시됩니다.
foo_2 foo_2 foo_2
며칠 동안이 작업을 수행하고 여러 번 다시 시작했습니다. 각 시간 제한 기능에 대해 ID를 올바르게 형식화하려면 어떻게해야합니까?
해봐 :
window.setTimeout( (function(time_, id_){
return function (event) {
id_.fadeIn(time_);
console.log(id_);
}
})(time,id),w);
이 값 저장하는 폐쇄입니다 time
및 id
함수의 범위를
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다