How to draw a dashed line on canvas and set the line dash pattern offset in JavaScript

1 Answer

0 votes
<canvas id="canvas"></canvas>
<script type="text/JavaScript">   

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

ctx.setLineDash([10, 15]);
ctx.lineDashOffset = 3;

ctx.beginPath();
ctx.moveTo(0, 100);
ctx.lineTo(450, 100);
ctx.stroke();

/*
run:  
  
- - - - - - - .
   
*/
  
</script>

 



answered May 25, 2016 by avibootz
...