Reputation: 911
I have code like this
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
};
And then I call the spinner like this:
var target = document.getElementById('foo');
var spinner = new Spinner(opts).spin(target);
//do other stuff here
spinner.stop();
But I want to delay the spinner for sometime before it stops. How to achieve this? Any help is appreciated.
Upvotes: 0
Views: 1453
Reputation: 7863
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);
This will call spinner.stop()
after 1000 milliseconds. You can change it to whatever you want.
Upvotes: 2
Reputation: 10191
You can use the setTimeout() method.
Your intialisation remains the same
var target = document.getElementById('foo');
var spinner = new Spinner(opts).spin(target);
Then you'd call
setTimeout(function(){spinner.stop()},5000);
After the given number of milliseconds the function will execute and stop your timer.
Upvotes: 0