2011-04-07 8 views
0

setTimeout을 사용하여 iOS 및 모바일 사파리에서 자바 스크립트로 일부 애니메이션을 수행하고 있습니다.모바일 사파리 javascript : 여러 setTimeouts 또는 setIntervals

동시에 두 개의 시간 제한이 정의되어있는 경우, 더 짧은 하나는 더 길어질 때까지 실행되지 않습니다.

setTimeout(a, 1000); 
setTimeout(b, 300); 

//it seems that both a and b will be called after 1000ms. 

같은 알려진 문제이다

setInterval을

일어날 것 같다? 예인 경우 해결 방법이 있습니까?

감사합니다.

답변

2

그건 그런 일이 아니야 ... 네가 다른 곳에서 문제가 될 수 있다고 생각해.

일부 다른 브라우저에서이 테스트를 시도해보십시오 http://jsfiddle.net/V6Ktd/

HTML :

<a href="#" onclick="timetest()">Test</a> 
<div>First fired at <span id="resultA"></span></div> 
<div>First fired at <span id="resultB"></span></div> 

JS : 크롬에서

function timetest() { 
    setTimeout(function() { 
     document.getElementById("resultA").innerText = "a:" + new Date().getTime(); 
    }, 1000); 
    setTimeout(function() { 
     document.getElementById("resultB").innerText = "b:" + new Date().getTime(); 
    }, 30); 
} 

테스트를 클릭 한 후 내가 볼 :

First fired at a:1302168904051 
First fired at b:1302168903081 

모바일 사파리에서 비슷한 결과가 나타납니다.

관련 문제