最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Canvas setLineDash and lineDashOffset NOT resetting in iOSSafari? - Stack Overflow

programmeradmin5浏览0评论

See fiddle here: /

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

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

Share Improve this question asked Feb 17, 2014 at 20:56 CodeXCDMCodeXCDM 2671 gold badge2 silver badges10 bronze badges 1
  • I think there is no support for setLineDash on mobile safari (iOS), at least in 6.x – tomasdev Commented Feb 25, 2014 at 20:02
Add a comment  | 

2 Answers 2

Reset to default 18

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

ctx.setLineDash([]);

I ran into similair behaviour, the only way to make Safari reset the lineDash was to use context.restore().

Adding

ctx.restore();

before drawing your non-dashed lines will work.

You will then have to reset other things like lineWidth off course.

发布评论

评论列表(0)

  1. 暂无评论