Skip to content Skip to sidebar Skip to footer

Canvas Animation Javascript Functions And Global Variables

Please, may someone help me! I am new in javascript. I want to make canvas animation using javascript. But I have the following error SCRIPT5007: Unable to get value of the proper

Solution 1:

This is happening because your executing the script before you create the canvas.

Create the canvas element FIRST then embed the javascript.

IE: canvasCircle is undefined because you can't get an element by ID that does not exist yet!

Solution 2:

I found the answer: the init() should be

functioninit() {
    s_canvas = document.getElementById("canvas_square");
    // Check if the canvas is supported and if the getContext is availableif (s_canvas && s_canvas.getContext) {
        s_context = s_canvas.getContext("2d");
        returnsetInterval(draw, 10);
    }
    else {
        alert("Canvas is not supported!");
    }
}

And the called of init() is replace with window.onload=init.

Solution 3:

Since you said that you are new to javascript, I believe that the problem could be that the browser on which you are running the code may not be supporting canvas.

Post a Comment for "Canvas Animation Javascript Functions And Global Variables"