javascript - image replacing with canvas doesn't work -
i have function converts images canvas.i tried replace created canvas within function related image using jquery .replacewith()
doesn't work.
js:
imgarray = $("img"); (var = 0; < imgarray.length; i++) { convertimagetocanvas(imgarray[i]); } function convertimagetocanvas(image) { var canvas = document.createelement("canvas"); canvas.width = image.width; canvas.height = image.height; canvas.getcontext("2d").drawimage(image, 0, 0); image.replacewith(canvas); }
you missing jquery selection apply replacewith
image:
replace this:
image.replacewith(canvas); // image here dom object, not jquery 1
with this:
$(image).replacewith(canvas); // here select image jquery, making jquery object
http://jsfiddle.net/ghkkq/
javascript jquery html5 html5-canvas image-conversion
No comments:
Post a Comment