Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canvas setLineDash and lineDashOffset NOT resetting in iOS/Safari?

See fiddle here: http://jsfiddle.net/mYdm9/4/

On my PC, doing

ctx.lineWidth=20;
ctx.setLineDash([20,30]); 
ctx.lineDashOffset=10;
ctx.beginPath();
ctx.moveTo(150,150);
ctx.lineTo(240,240);
ctx.lineTo(180,40);
ctx.stroke();
ctx.closePath()

Gives the first set of lines, with the desired dashes/offsets

Now with

ctx.setLineDash([0,0]); 
ctx.lineDashOffset=0

in the next batch of commands:

ctx.beginPath();
//resets line dash... except on iOS Safari it seems...
ctx.setLineDash([0,0]); 
ctx.lineDashOffset=0;
ctx.moveTo(0,300);
ctx.lineTo(0,250);
ctx.lineTo(100,400);
ctx.lineTo(200,300);
ctx.stroke();
ctx.closePath()

After the first set of lines seems to reset any dash properties. Get solid lines again

On an iPad2 running Safari... it seems completely ignored, the lines stay dashed. Why is this? Also, is there some other method to properly resetting line dashes...? (preferably working cross browser/OS)

Thanks

like image 816
CodeXCDM Avatar asked Feb 17 '14 20:02

CodeXCDM


1 Answers

Use this notation, it will work in all browsers that supports setLineDash

ctx.setLineDash([]);
like image 185
Milan Bydžovský Avatar answered Nov 12 '22 00:11

Milan Bydžovský