How to get the line and space width of a drawn line with dash pattern on canvas 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([7, 13]);
document.write(ctx.getLineDash()); 

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

/*
run:  
  
- - - - - - -
 7,13   
   
*/
  
</script>

 



answered May 25, 2016 by avibootz

Related questions

...