I want to use Spin.js to display a spinner. I can do it but i can't stop it.
My code :
function startSpin() {
var target = document.getElementById('demarrer');
new Spinner().spin(target);
setTimeout("dummyFunc()", 4000);
}
function dummyFunc() {
console.log("bouh");
}
What I have to call in order to stop the spinner ?
I have tried :
And no results... ='(
Thx !
First of all I have to say that I have never used Spinner and have no idea how it works, but I'm fairly sure that the problem is that you're just throwing away the Spinner instance after you create it. Instead of
new Spinner().spin(target);
Try to write
var spinner = new Spinner().spin(target);
Then, to stop the spinner, write:
spinner.stop();
Complete code:
function startSpin() {
var target = document.getElementById('demarrer');
var spinner = new Spinner().spin(target);
// Run a function after 4 seconds.
setTimeout(function() {
console.log("bouh");
spinner.stop(); // Stop the spinner
}, 4000);
}