Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript Need a Pause

JavaScript forum,
I have been writing C, C++ and many kinds of code for many years and am currently learning HTML, CSS and JavaScript. I have some HTML and CSS working and am adding JavaScript. Since I'll be doing some animation I need to find out how to execute something like this:

<script>
execute some JavaScript to draw in a canvas. I can do this.
wait for some time in ms. I've tried loops and several other things I found on the internet but none work.
execute some JavaScript that draws more things in the canvas.
</script>

jerdonald
 
Try using setTimeout()

HTML:
<script>
//execute some JavaScript to draw in a canvas. I can do this.
setTimeout( function() {
  //execute some JavaScript that draws more things in the canvas.
}, /*time in ms*/);
</script>
 
Johna,
Thanks for the response.

Following your suggestion I tired this code:

setTimeout( drawCircle() {
ctx.beginPath();
ctx.arc(100, 75, 50, 0, 2 * Math.PI);
ctx.stroke();
}, 2000);

Now my file only displays the canvas with nothing inside it?

jerdonald
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom