Excanvas vml positioning issue

2019-04-12 20:54发布

问题:

I've slogged my way through implementing excanvas on ie8. I've got the dynamic element bit sorted, the initially-hidden elements are now happily rendering throughout most of the app, and just when all seemed to be well I've hit another roadblock. The vml items rendered inside the div that excanvas generates are all offset by a large amount.

I only discovered what was happening by setting overflow:visible on all children of canvas, which caused the offset vml to become visible.
I've got a screenshot of the offending articles; the area in blue is the generated div in the correct position, and the items bordered in red should be within the blue area.

Has anyone encountered this before, and even better, been able to solve it?

Cheers!

回答1:

In case anyone ever encounters this error, it seems the issue was with a translate() call. Although I was using save and restore, and every standard implementation of canvas interpreted the translate call as I intended, in excanvas the translate was persistently additive.

I solved the issue by restoring the identity matrix before performing the other save, translate & restore calls.

context.setTransform(1,0,0,1,0,0);