html5 - .height/width of div returning different values into canvas -
above test website i'm trying out new html5 canvas tag. i've stripped down bit make relevant code easier locate.
the issue i'm having when setting width , height of canvas values i'm getting .height , .width methods larger div i'm trying them causing canvas overrun encapsulating div.
link jsbin:
http://jsbin.com/ejivux/13/edit
code incase people want in here:
html:
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <meta charset=utf-8 /> <title>js bin</title> </head> <body> <div id="container"> <div id="leftcolumn"> text </div> <div id="rightcolumn"> </div> </div> </body> </html> css:
canvas{ border-width:5px; border-style:solid; } html{ height:99%; background-color:red; } body{ height:99%; background-color:blue; } #container{ background-color:yellow; min-width:976px; min-height:99%; height:100%; } #leftcolumn{ background-color:pink; width:50%; min-height:100%; height:100; float:left; } #rightcolumn{ background-color:green; width:50%; min-height:100%; height:100%; float:left; } js:
var canvasdiv = document.getelementbyid('rightcolumn'); canvas = document.createelement('canvas'); canvas.setattribute('width', $('#rightcolumn').width()); canvas.setattribute('height', $('#rightcolumn').height()); canvas.setattribute('id', 'canvas'); canvasdiv.appendchild(canvas);
your canvas has 5px border:
canvas{ border-width:5px; border-style:solid; } so if set width of canvas of containing div expect overall width of canvas 10px more div because of border on both sides. try this:
canvas.setattribute('width', $('#canvasdiv').width()-10); canvas.setattribute('height', $('#canvasdiv').height()-10);
Comments
Post a Comment