var intervalHandle ;
var currentOpacity=0;
function beginAnimate() {
current_question_div = document.getElementById(current_question);
intervalHandle = setInterval(function(){
animateBox(current_question_div)
}, 200);
alert("Hellow ashik !");
}
function animateBox(current_question_div) {
current_question_div.style.backgroundColor = "lightblue";
currentOpacity = currentOpacity + .091;
current_question_div.style.opacity = currentOpacity;
if(currentOpacity > 1) {
alert("END");
clearInterval(intervalHandle);
}
}
<P onclick="beginAnimate">Click</p>
모든 것이 괜찮 자바 스크립트 setInterval을 기능을 실행하지만, alert("Hellow ashik !");
. clearInterval
이 발생했을 때 alert("Hellow ashik !")
을 열려고합니다. 이제는 다른 JavaScript 코드도 간격이 실행되는 동안 병렬로 실행됩니다. 한 번에 하나의 스레드 만 실행해야합니다. 도와주세요. 이 코드를 하나씩 실행하는 방법이 있습니까? 감사.만 간격이 실행되는 동안 작업
다른 스레드가 없으므로 JS가 병렬로 실행되지 않습니다. 간격은 * 비동기 적으로 * 실행됩니다. – Bergi
코드가 "하나씩"실행 중입니다. * setInterval *을 호출하면, 전달 된 함수는 최소한 200ms 동안 호출되지 않지만 코드의 다음 행 ('alert ('...')')은 즉시 호출됩니다. 하나의 스레드 만 작동합니다. 자바 스크립트는 단일 스레드이므로, * beginInitval *에 전달 된 함수는 * beginAnimate *가 완료 될 때까지 실행할 수 없습니다 (간격을 0으로 설정하더라도). – RobG