2014-01-20 75 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

@ Lath是的,這就是我想要它做的 – 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