I followed textbooks on creating a canvas, however it doesnโt work, and not one of them is painted on it. Do I need to have a script in <head> ? Any help would be appreciated!
Here's a JSFiddle with my code.
<!DOCTYPE html> <html> <head> <title>Simple animations in HTML5</title> </head> <body> <h2> Optical Illusion </h2> <video id="illusion" width="640" height="480" controls> <source src="Illusion_movie.ogg"> </video> <div id="buttonbar"> <button onclick="changeSize()">Big/Small</button> </div> <p> Watch the animation for 1 minute, staring at the centre of the image. Then look at something else near you. For a few seconds everything will appear to distort. Source: <a href="http://en.wikipedia.org/wiki/File:Illusion_movie.ogg">Wikipedia:Illusion movie</a> </p> <script> var myVideo=document.getElementById("illusion"); var littleSize = false; function changeSize() { myVideo.width = littleSize ? 800 : 400; littleSize = !littleSize;</script> <canvas id= "myCanvas " width= "500 " height= "500 "> style="border:1px solid #000000;"> </canvas> <script> var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.fillStyle = "blue"; context.fillRect(20, 50, 200, 100); </script> </body> </html>
source share