javascript - Responsive Canvas in Bootstrap -
javascript - Responsive Canvas in Bootstrap -
i'm trying responsive canvas. tests has been doing 600x600 canvas , height , width works ok , paint every line correctly. problem have tried this:
#mycanvas { background-color: #ffffff; border:1px solid #000000; min-height: 600px; height: 100%; width: 100%; }
just record, mycanvas within sm-col-8.
and looks nice on laptop , looks nice on phone (because of draw() function, because thinking square) draw starts more in down-left corner (nearby) , should start @ up-right corner.
so, don't want alter draw() function i'm looking reescale canvas size. mean: if i'm in laptop/tablet.. 600x600, show @ size, if i'm on phone has 384x640 show 300x300? don't know if solution.
my draw function:
function drawlines(lines,i,table,xtotal,ytotal){ var c = document.getelementbyid("mycanvas"); var ctx = c.getcontext("2d"); var xini; var xfin; var yini; var yfin; xini = (c.width*parseint(lines[i][1])/xtotal); yini = (c.height*parseint(lines[i][2])/ytotal); xfin = (c.width*parseint(lines[i][3])/xtotal); yfin = (c.height*parseint(lines[i][4])/ytotal); ctx.beginpath(); ctx.moveto(xini,c.height-yini); ctx.lineto(xfin,c.height-yfin); ctx.linewidth=4; ctx.strokestyle = coloraleatorio(); ctx.stroke(); }
with bootstrap, use:
<canvas id="canvas" class='img-responsive' style="border: 1px solid black;"></canvas>
javascript css html5 canvas twitter-bootstrap-3
Comments
Post a Comment