2015년 8월 19일 수요일

javascript-delay

setTimeout( function, mile second );
ex) setTimeout("helloworld()", 1000);    // 1000 mile second == 1 second

일정시간 딜레이만 주려면 아래와 같은 함수를 만들어 사용하면 된다.

function delay(gap){ /* gap is in millisecs */
  var then,now;
  then=new Date().getTime();
  now=then;
  while((now-then)<gap){
    now=new Date().getTime();  // 현재시간을 읽어 함수를 불러들인 시간과의 차를 이용하여 처리
  }
}

댓글 없음:

댓글 쓰기