dash-1.html 728 B

1234567891011121314151617181920212223242526272829303132333435
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. window.onload = function() {
  5. var ctx = document.getElementById("c1").getContext("2d");
  6. ctx.lineWidth = 5;
  7. ctx.setLineDash([ 5, 10 ]); // 5 on, 10 off
  8. ctx.moveTo(50, 50);
  9. ctx.lineTo(250, 50);
  10. ctx.stroke();
  11. ctx.beginPath();
  12. ctx.lineDashOffset = 5;
  13. ctx.moveTo(50, 100);
  14. ctx.lineTo(250, 100);
  15. ctx.stroke();
  16. ctx.beginPath();
  17. ctx.lineDashOffset = 5;
  18. ctx.setLineDash([ 5 ]); // 5 on, 5 off
  19. ctx.moveTo(50, 150);
  20. ctx.lineTo(250, 150);
  21. ctx.stroke();
  22. ctx.beginPath();
  23. }
  24. </script>
  25. </head>
  26. <body style="padding: 0px; margin: 0px;">
  27. <div><canvas id="c1" width="300" height="300"></canvas></div>
  28. </body>
  29. </html>