Javascript examples for Canvas:Example
Simple Html5 Canvas operation
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){/* w w w . java 2s . c o m*/ function Canvas(name){ this.ctx=document.getElementById(name).getContext('2d'); this.canvas=this.ctx.canvas; this.width=this.canvas.width; this.height=this.canvas.height; this.layers=new Array(); this.draw = function() { this.canvas.width = this.canvas.width; this.ctx.beginPath(); this.ctx.rect(0,0,this.width,this.height); this.ctx.closePath(); this.ctx.fillStyle="#eaeaea"; this.ctx.fill(); this.ctx.beginPath(); this.ctx.rect(250,50,300,250); this.ctx.closePath(); this.ctx.fillStyle="#ff0000"; this.ctx.fill(); intensity=Math.random(); this.flash(intensity); }; this.flash = function(intensity) { this.ctx.globalAlpha = intensity; this.ctx.beginPath(); this.ctx.rect(0,0,this.width,this.height); this.ctx.closePath(); this.ctx.fillStyle="#fff"; this.ctx.fill(); this.ctx.globalAlpha = 1; setTimeout(this.draw.bind(this),1000/12); }; } function initCanvas(){ mycanvas=new Canvas('myCanvas'); mycanvas.draw(); } $(document).ready(function() { initCanvas(); }); }); </script> </head> <body> <canvas id="myCanvas" style="border: solid" width="500" height="500"></canvas> </body> </html>