作成したポイントをキャンバスの特定の部分に移動する必要のあるアプリケーションがあります。どうしたらいいですか?あなたのdiv..Exampleをドラッグするキャンバス内のポイントを動的にドラッグする
$("#canvas").click(function(e){
getPosition(e);
});
var pointSize = 1;
function getPosition(event){
var rect = canvas.getBoundingClientRect();
var x = event.clientX - rect.left;
var y = event.clientY - rect.top;
console.log(x,y)
drawCoordinates(x,y);
}
function drawCoordinates(x,y){
var ctx = document.getElementById("canvas").getContext("2d");
ctx.fillStyle = "#ff2626"; // Red color
ctx.beginPath();
ctx.arc(x, y, pointSize, 0, Math.PI * 2, true);
ctx.fill();
}
だから、それは新しいポイントを作成する必要があり、既存のポイントをクリックした場合は、それをドラッグすることができるはずですか? –
@ManuelOttoはい!まさに! – yavg