Calling a function at certain interval of time

Here is the piece of code that helps you to update a function at certain interval of time. The time is usually calculated in milliseconds. As you can see the code has 1000 somewhere in the setinterval function. This code helps to call the function every second. Here in the first line you can see the ‘mainCanvas’. It is nothing but the id of HTML5 canvas.

var drawingCanvas = document.getElementById(‘mainCanvas’);
if(drawingCanvas.getContext) {
    /* Initaliase a 2-dimensional drawing context */
    var context = drawingCanvas.getContext(‘2d’);
    setInterval(“update()”,1000);

}

function update(){
//call the function which you want to update.

}

All right test the code and see the result. Happy Coding…. Smile

Leave a Reply

Your email address will not be published. Required fields are marked *

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site
%d bloggers like this: