html - how to create a canvas dynamically in javascript -


i have canvas can draw things mouse.. when click button has capture drawing , add right under canvas, , clear previous 1 draw new..so first canvas has static , other ones has created dynamically drawing draw .. should can help

here jsfiddle http://jsfiddle.net/dqppk/378/

var canvas = document.getelementbyid("canvas"), ctx = canvas.getcontext("2d"), painting = false, lastx = 0, lasty = 0; 

here's function use this, part of library made , use ease few things canvas. put on github in case other function might be of use, i'll have make readme later...

https://github.com/gamealchemist/canvaslib

with namespaceing removed, code follow insert canvas :

// insert canvas on top of current document. // if width, height not provided, use document width / height // width / height unit css pixel. // returns canvas. insertmaincanvas = function insertmaincanvas (_w,_h) {    if (_w==undefined) { _w = document.documentelement.clientwidth & (~3)  ; }    if (_h==undefined) { _h = document.documentelement.clientheight & (~3) ; }    var maincanvas = ga.canvaslib.createcanvas(_w,_h);    if ( !document.body ) {            var anewbodyelement = document.createelement("body");                document.body = anewbodyelement;     };    document.body.appendchild(maincanvas);    return maincanvas; } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -