How hidden spinner in spin.js?
-
01-07-2021 - |
Frage
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 :
- Spinner().stop(target);
- Spinner().spin(target).stop();
- Spinner().stop();
And no results... ='(
Thx !
Lösung
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);
}
Andere Tipps
You should modify your setTimeout
.
var spinner = Spinner().spin(target);
setTimeout(function() {
dummyFunc();
spinner.stop();
}, 4000);
From the piece you gave us, I'd guess that new Spinner
creates an object, on which you need to call the stop
method:
var target = /* some DOM element */;
var spinner = new Spinner();
spinner.spin(target);
spinner.stop(target);
The spinner will stop after 4 seconds
var target = document.getElementById('searching_spinner_center');
var spinner = new Spinner(opts).spin(target);
setTimeout(function() {
spinner.stop();
}, 4000);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow