0
所以,我得出一个多边形用下面的代码:在html5中,JavaScript有没有办法让一个多边形,我只绘制拖动?或听听鼠标事件?
var canvas = document.getElementById("polyCanvas");
var c2 = canvas.getContext("2d");
var coords = '';
c2.clearRect(0, 0, 2000, 2000);
$("fdel").remove();
$("#eliminar" + todelete).remove();
c2.beginPath();
var first = true;
var points = 1;
var done = false;
$("#vertexcontainer .vertex").each(function() {
var position = $(this).position();
var x = 2+position.left;
var y = 2+position.top;
if (!done){
if (first) {
c2.moveTo(x, y);
first = false;
} else {
c2.lineTo(x, y);
}
}
if(points > cpoints){
done = true;
}
points = points + 1;
coords = coords + x + ',' + y + ' ';
});
$('#coordinates').val(coords);;
c2.closePath();
c2.lineWidth = 2;
c2.strokeStyle = '#ff0000';
c2.stroke();
c2.fillStyle = "rgb(0, 100, 200)";
c2.fill();
它运行顺利,但我希望能够拖动多边形,或者使用鼠标事件与它。那可能吗?
我的天真尝试做c2.hover(功能......,和c2.addeventlistener ......一直没成功的=(
我认为这是对你有帮助的,完整的答案:http://stackoverflow.com/questions/19100009/拖动和调整大小-AN-图像上HTML5的画布 – klauskpm