I want to dynamically resize the canvas size according to the content of a DIV. i am using the following Code but it doesn't seems to work.
<canvas id="canvas1" width="800" height="2000" > <canvas>
Javascript
document.getElementById("canvas1").style.height = document.getElementById("div").style.height;
document.getElementById("canvas1").style.width= document.getElementById("div").style.width;
Also i want that the canvas is loaded automati开发者_StackOverflowcally , How should i do that ? on a $(document).ready
event ?
How shall i do that too ?
Use offsetWidth
to get the dimensions of the element (including borders).
// loaded automatically on page load
window.onload = function() {
var div = document.getElementById("div");
var canvas = document.getElementById("canvas1");
canvas.height = div.offsetHeight;
canvas.width = div.offsetWidth;
}
精彩评论