ctx.setLineDash() 方法设置虚线的线段与间隔的数值, 比如: ctx.setLineDash([20, 5]) 表示线段长度为20px, 间隔为5px;

ctx.lineDashOffset 属性设置起始的偏移量.

function draw() {
    var canvas = document.getElementById('canv');
    if (!canvas.getContext) return;
    var ctx = canvas.getContext("2d");

    ctx.setLineDash([20, 5]);  // [实线长度, 间隙长度]
    ctx.lineDashOffset = -0;
    ctx.strokeRect(50, 50, 210, 210);
}
draw();

怎样设置虚线样式

 

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-01-12
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-12
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案