Search code examples
javascripthtmlcanvasmobile-safari

How to remove dashed line from HTML context


To draw a dashed line in a canvas context, I use this

    var canvas = document.getElementById('canv');
    ctx = canvas.getContext('2d');        
    ctx.setLineDash([5]);

When I don't want to draw more dashed lines I do this.

    ctx.setLineDash([0]);

Removing the dashs works in desktop browsers, but this is not working in mobile Safari. Is there another way to remove the dashes and draw plain continious solid lines?

Thanks


Solution

  • Wrap your code inside context.save / context.restore

    ctx.save();
    ctx.setLineDash([5]);
    // draw dashed stuff
    ctx.restore();
    
    // now the default solid line is restored