Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can't change text javascript

I tried to make an animation on javascript.

It should look like:

Frame 1:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ඞ______ _

Frame 2:

_ඞ_____ _

Frame 3:

__ඞ____ _

Frame 4:

___ඞ___ _

I want to something that changes the text after some seconds. So I’ve got a label and this is a snippet of a code.

document.getElementById('label').innerHTML='ඞ______ _';

sleep(500);

But if I use the sleep function, the page ‘waits’ until my ‘animation’ is finished and then I can see the last text:

___ඞ___ _

Is there a way to solve this problem?

>Solution :

You should use a async function for updating the animation at the same time of doing the other stuff your javascript is doing.

an async function looks like this

async renderAnimation () {
    setTimeout(() => {this.animate() }, 500);  
}

animate(){
    document.getElementById('label').innerHTML='ඞ______ _';
}

You should check this link for a more in deep explanation of async: https://www.w3schools.com/js/js_async.asp

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading