I am a newbie to HTML5 and JavaScript, I know there's a lot of libraries can do that, but I am wondering if there's a way to do it just using plain javascript.
I have a canvas and when the canvas is clicked somewhere, there will be a little red dot appear at where the user clicked. I want to make each of the little dot draggable, any ideas on it? thanks.
Here's the code I have:
in HTML:
<div id="primal_plane" style="position:absolute; top:100px; left:10px;"> <canvas id="canvas_prime" onclick="drawDot('canvas_prime')" width="700" height="500"></canvas> </div> in JS file:
function drawDot(plane) { var canvas = document.getElementById(plane); var context = canvas.getContext("2d"); context.beginPath(); context.arc(mouseX * 50, mouseY * 50, 4, 0, 2 * Math.PI, false); context.fillStyle = 'green'; context.fill(); context.lineWidth = 1; context.strokeStyle = 'yellow'; context.stroke(); }