admin管理员组文章数量:1201791
I hit a weird edge case building something with canvas at work. clearRect does not clear the canvas when drawing vertical lines that go from the top to the bottom of the canvas. When rendering other stuff, clearRect works fine.
I'm not sure if I am missing something obvious, if this is intentional behavior, or a browser bug (unlikely since the behavior is identical in chrome, safari, firefox and opera on mac). If it is intentional behavior, does anybody know the rationale behind it and/or can perhaps point to some documentation?
I made a small test case that shows the behavior clearly, only the combination clearRect/vertical lines does not clear the canvas: /
Thanks!
I hit a weird edge case building something with canvas at work. clearRect does not clear the canvas when drawing vertical lines that go from the top to the bottom of the canvas. When rendering other stuff, clearRect works fine.
I'm not sure if I am missing something obvious, if this is intentional behavior, or a browser bug (unlikely since the behavior is identical in chrome, safari, firefox and opera on mac). If it is intentional behavior, does anybody know the rationale behind it and/or can perhaps point to some documentation?
I made a small test case that shows the behavior clearly, only the combination clearRect/vertical lines does not clear the canvas: http://jsfiddle.net/kZj6F/
Thanks!
Share Improve this question asked Mar 14, 2012 at 11:49 bwindelsbwindels 2,0841 gold badge17 silver badges20 bronze badges1 Answer
Reset to default 26Your issue is with a missing beginPath
causing subsequent lines to be added to the same path that was stroke
drawing all lines.
If you switch to dots and back to lines with the clearRect option choose you can see the last arc
added to the path being drawn too. Just add a call ctx.beginPath();
prior ctx.moveTo(randomX + 0.5, 0); ctx.lineTo(randomX + 0.5, canvas.height);
and the problem is solved.
You can check http://jsfiddle.net/kZj6F/1/ to see it working.
Bwt it will with other shapes too if they got added to the path and the path was not cleared.
本文标签: javascriptclearRect does not clear the canvas when drawing vertical linesStack Overflow
版权声明:本文标题:javascript - clearRect does not clear the canvas when drawing vertical lines - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738606413a2102372.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论