I want to draw circle on responsive canvas using javascript. I am getting width and height of canvas, but because of div tag width and height % I am able to draw circle properly. The div tag width and height are in % because I want to show 5 canvas on single page. Is there any alternative way to place 5 canvas on single page and draw a circle in each canvas using height and width of canvas? One more thing, I don't want absolute position because as per browser width I want to change canvas position
Image : 192.168.10.29/1.png
CSS
.all
{
width:30%;
height:45%;
float:left;
}
canvas
{
width:100%;
height:100%;
}
HTML
<div id='container'>
<div class='all'>
<canvas id='clock1' style="border:solid">
</div>
<div class='all'>
<canvas id='clock2' style="border:solid">
</div>
<div class='all'>
<canvas id='clock3' style="border:solid">
</div>
<div class='all'>
<canvas id='clock4' style="border:solid">
</div>
<div class='all'>
<canvas id='clock5' style="border:solid">
</div>
</div>
Javascript
function draw(canvasarray)
{
var clock = document.getElementById(canvasarray);
var style = getComputedStyle(document.getElementById(canvasarray));
var height = parseInt(style.getPropertyValue("height"),10);
var width = parseInt(style.getPropertyValue("width"),10);
var radius = 0;
console.log('Width : ' + width + ' Height : ' + height);
if(width < height)
{
radius = width/2;
}
else
{
radius = height/2;
}
console.log('Radius : '+ radius);
var ctx = clock.getContext('2d');
ctx.beginPath();
ctx.arc(width/2,height/2,radius,0,Math.PI*2);
ctx.stroke();
}