Looking for a way to chain functions with delays? Here is an example of what I have tried:
Promise.resolve()
.then(setKeyframe('keyframe-0'))
.then(delay(3000))
.then(setKeyframe('keyframe-1'))
.then(delay(3000))
.then(setKeyframe('keyframe-2'))
;
function delay(ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms);
});
}
function setKeyframe (name) {
var elem = document.getElementsByClassName('animation-container')[0];
elem.className = 'animation-container ' + name;
}
However, all the functions appear to be executed one after the other without any delay. The delay function does not seem to work as expected in this chaining process. What could be the issue here?