Can I resolve the following issue with the use of a Promise? I am grabbing the body
element and setting a 5s
transition on it to increase height and then having the function call itself again to reduce the height, and so on and so on. The obvious issue is that function will repeatedly call itself before the font size has finished transitioning.
function swap(height=null) {
let body = document.body;
console.log("height = " , height);
if (!height || height == '50px') {
height = '20px'
} else {
height = '50px'
}
[...body.children].forEach(child => {
child.style.fontSize = height;
child.style.transition = 'all 5s ease';
});
swap(height)
}
I think one solution would be to just wrap the swap(height)
in a setTimeout but is there any way a Promise can be used here? I am still trying to wrap my head around use-cases for them.