Is it possible to "draw" the content of a div to a canvas... i have done the div manipulation with css, but need canvas to "save" the content to jpg with the .dataToURL function
so the question is... do you know a HTML, CSS, jQuery function that transfer the content of a div and draw it to a canvas
thanks in advance
You cannot place elements inside a canvas (and have both displayed); they are only displayed if the browser does not understand the canvas element.
According to the HTML specification you can't access the elements of the Canvas. You can get its context, and draw in it manipulate it, but that is all. BUT, you can put both the Canvas and the html element in the same div with a a position: relative and then set the canvas and the other element to position: absolute .
The canvas element is part of HTML5 and allows for dynamic, scriptable rendering of 2D shapes and bitmap images.
Html5 Canvas is an artbook with a pencil. A Div is the desk you put the Canvas on to.
<canvas>
does not directly support placing HTML content on it, as combining this with <IFRAME>
could potentially lead to lost of private information.
What you can do is that you dynamically create SVG image and then draw this on <canvas>
. SVG has better support for rich-text formatting than <canvas>
.
jQuery library for dynamic SVG creation:
http://keith-wood.name/svg.html
(See Text example)
Check out html2Canvas, it takes a dom element and converts it to a canvas, and then you can draw that canvas onto another canvas something like this:
http://html2canvas.hertzen.com/
var domElement = document.getElementById('myElementId');
html2canvas(domElement, {
onrendered: function (domElementCanvas) {
var canvas = document.createElement('canvas');
canvas.getContext('2d').drawImage(domElementCanvas, 0, 0, 100, 100);
// do something with canvas
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With