0
我正在尝试编写一个函数,该函数可以在html画布中绘制给定xy坐标,宽度和高度的曲线矩形,但是当前我的脚本会输出空白画布。为什么代码不能绘制矩形?Javascript - 绘制曲线矩形的函数
var c=document.getElementById(id);
var ctx=c.getContext('2d');
function makeCurvedRect(x, y, w, h) {
ctx.beginPath();
ctx.moveTo(x+10, y);
ctx.lineTo(x+w-10, y);
ctx.quadraticCurveTo(x+w, y, x+w, y+10);
ctx.lineTo(x+w, y+h-10);
ctx.quadraticCurveTo(x+w, y+h, x+w-10, y+h);
ctx.lineTo(x+10, y+h);
ctx.quadraticCurveTo(x, y+h, x, y+h - 10]);
ctx.lineTo(x, y+10);
ctx.quadraticCurveTo(x, y, x+10, y);
ctx.stroke();
}
makeCurvedRect(162.5,40,175,175);
看来你在ctx.quadraticCurveTo(x,y +)行遇到语法错误h,x,y + h - 10]);让我们删除']'并重试 –