I am currently working on a website project that requires multiple canvases to encircle individual images.
After experimenting with HTML, CSS, and JS on JSfiddle, I successfully achieved the desired effect with a single image. However, when I duplicated the HTML code, the second canvas was not created (or perhaps it overlapped with the first one?)
How can I modify the code so that each image has its own corresponding canvas?
var canvas = document.getElementById('border');
var context = canvas.getContext('2d');
var x = 58;
var y = 58;
var radius = 55;
var startAngle = 1.5 * Math.PI;
var endAngle = 1 * Math.PI;
var counterClockwise = false;
context.beginPath();
context.arc(x, y, radius, 0, 2 * Math.PI, false);
context.lineWidth = 3;
// line color
context.strokeStyle = '#ebebeb';
context.stroke();
context.beginPath();
context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
context.lineWidth = 4;
context.strokeStyle = '#8aff92';
context.stroke();
.pkmn
{
position: relative;
display: inline-block;
margin: 5px;
width: 116px;
height: 116px;
}
.pkmn .sprite
{
padding: 5px;
position: relative;
top: 5px;
left: 5px;
z-index: -1;
}
// Remaining CSS styles skipped for brevity
<div class="pkmn">
<canvas id="border" class="exp" width="115" height="115"></canvas>
<div class="lvl">95</div>
<img alt="test" src="http://cdn.bulbagarden.net/upload/7/76/Spr_5b_143_s.png" class="sprite">
<img alt="item" src="http://cdn.bulbagarden.net/upload/0/0f/Bag_Leftovers_Sprite.png" class="item">
<img alt="crown" src="http://cdn.bulbagarden.net/upload/c/c5/Leaf_Crown_Sprite.png" class="crown">
<img alt="star" src="http://cdn.bulbagarden.net/upload/2/27/ShinyVIStar.png" class="star">
<img alt="heart" src="http://i1055.photobucket.com/albums/s519/impojr/heart_zpsdaihll9m.png" class="heart">
</div>
// Second set of HTML elements for another image and canvas