I have this : https://jsfiddle.net/ahhc9tjn/
The problem is about this two functions :
this.addShipTest1 = function() {
this.revolutionTime += 0.5;
this.stopAllShipCSS();
this.addShip()
}
this.addShipTest2 = function() {
this.revolutionTime += 0.5;
this.stopAllShipCSS();
var save = this;
setTimeout(function() {
save.addShip();
}, 100);
}
Why do I have to wait to make this work ? I mean the functions are not asynchronous, so should
addShip()
Be call only after
stopAllShipCSS()
The problem is that, in addShipTest1, the stop is "call after" or "ignore"... (The JSFiddle show the problem).
Edit :
Solutions I tried, but that doesn't succeed :
(1)
$.when(this.stopAllShipCSS()).then(this.addShip());
(2)
var it = 0;
var save = this;
this.ships.forEach(function(ship) {
ship.css({
'animation':''
});
it++;
if (it == save.ships.length) {
save.addShip();
}
});