说我们drawed在HTML5画布多个矩形:如何识别点击上绘制的矩形在画布上
context.fillStyle='black';
context.fillStroke='black';
context.beginPath();
for(var i=0; i<50; i++)
{
context.rect(i*20,i*20,w,h);
//this is just some random configuration for the rectangles, it doesn't really matter how they are positioned
}
context.closePath();
context.fill();
context.stroke();
我怎样才能使它所以它的识别时,对单个矩形用户点击后,说,改变它的颜色?
是否有可能或将不得不做一个函数,它需要鼠标的x和y坐标,然后检查它的着陆点与矩形的x和y坐标相比,最终找到一个“覆盖”鼠标坐标?
看看这个命中测试(可能是重复的)计算器后:http://stackoverflow.com/questions/15176968/how-to-change-mouse-over-to-onclick/15179322#15179322 – markE