2014-01-20 2 views
0

내가 가진이멈추기 전에 Spin.js 스피너를 지연시키는 방법?

var opts = { 
    lines: 11, // The number of lines to draw 
    length: 28, // The length of each line 
    width: 25, // The line thickness 
    radius: 35, // The radius of the inner circle 
    corners: 1, // Corner roundness (0..1) 
    rotate: 0, // The rotation offset 
    direction: 1, // 1: clockwise, -1: counterclockwise 
    color: '#000', // #rgb or #rrggbb or array of colors 
    speed: 1.3, // Rounds per second 
    trail: 61, // Afterglow percentage 
    shadow: false, // Whether to render a shadow 
    hwaccel: false, // Whether to use hardware acceleration 
    className: 'spinner', // The CSS class to assign to the spinner 
    zIndex: 2e9, // The z-index (defaults to 2000000000) 
    top: 'auto', // Top position relative to parent in px 
    left: 'auto' // Left position relative to parent in px 
}; 

그리고 내가 스피너과 같이 호출과 같은 코드 :

var target = document.getElementById('foo'); 
var spinner = new Spinner(opts).spin(target); 
//do other stuff here 
spinner.stop(); 

하지만 멈출 언젠가 전에 스피너를 연기하고 싶다. 이것을 달성하는 방법? 어떤 도움을 주셔서 감사합니다.

+0

지연이란 정확히 무엇을 의미합니까? 최소한 x 초 동안 회전 시키길 원하십니까? – Liath

+0

@Liath 네, 그게 내가하고 싶은거야 – n00b

답변

0

setTimeout() 메서드를 사용할 수 있습니다.

귀하의 intialisation는

var target = document.getElementById('foo'); 
var spinner = new Spinner(opts).spin(target); 

같은

가 그런 다음 함수가 실행하고 타이머를 중지 밀리 초 주어진 수의 후

setTimeout(function(){spinner.stop()},5000); 

를 호출 할 것이다 남아있다.

2
var target = document.getElementById('foo'); 
var spinner = new Spinner(opts).spin(target); 
//do other stuff here 
// use setTimeout to add a delay to the stop 
setTimeout(function(){ 
spinner.stop(); 
}, 1000); 

1000 밀리 초 후에 spinner.stop()을 호출합니다. 원하는대로 변경할 수 있습니다.

+0

위대한 마음! 내가 할당량을 사용했음을 +1 할 수 없어 죄송합니다. ( – Liath

관련 문제