Drawing Dashed lines on HTML5 Canvas?

后端 未结 5 856
盖世英雄少女心
盖世英雄少女心 2020-12-29 20:31

I would like to draw some dashed lines on HTML5 canvas. But I couldn\'t find there is such a feature. the canvas path could only draw solid lines. And people have tried to u

5条回答
  •  长情又很酷
    2020-12-29 21:06

    This is an easier way to create dashed lines :

    var canvas = document.getElementById("canvas");
    var ctx = canvas.getContext("2d");
    
    ctx.setLineDash([5, 15]);
    
    ctx.beginPath();
    ctx.moveTo(0,100);
    ctx.lineTo(400, 100);
    ctx.stroke();
    

    Hope that helps.

提交回复
热议问题