我是Javascript的新手,我正在制作基于Web的项目(HTML).凭借我的基本知识,我设法创建了一个表单并在其上绘制了一个矩形.
我现在希望能够点击矩形,像按钮一样使用它,但我似乎无法找到任何可以帮助我的教程或答案.
这是我的矩形的代码:
function Playbutton(top, left, width, height, lWidth, fillColor, lineColor) {
context.beginPath();
context.rect(250, 350, 200, 100);
context.fillStyle = '#FFFFFF';
context.fillStyle = 'rgba(225,225,225,0.5)';
context.fillRect(25,72,32,32);
context.fill();
context.lineWidth = 2;
context.strokeStyle = '#000000';
context.stroke();
context.closePath();
context.font = '40pt Kremlin Pro Web';
context.fillStyle = '#000000';
context.fillText('Start', 345, 415);
}
Run Code Online (Sandbox Code Playgroud)
我知道你需要找到x,y坐标和鼠标位置才能点击矩形区域.但我现在真的陷入困境.它可能非常简单和逻辑,但我们都必须经历这个阶段.