首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Canvg -画布对摩丝表情的改变

Canvg -画布对摩丝表情的改变
EN

Stack Overflow用户
提问于 2016-04-06 11:47:54
回答 1查看 377关注 0票数 1

我使用拉布来将一些SVG呈现到图像中。目前SVG到画布部分的工作还不错。但是,当指针进入画布时,我无法确定生成的画布为什么会发生变化。我真的需要复制生成的画布,还是我遗漏了什么?

代码语言:javascript
复制
svgElement.each(function () {
    var canvas = document.createElement("canvas");
    //convert SVG into a XML string
    var xml = (new XMLSerializer()).serializeToString(this);
    // Removing the name space as IE throws an error
    xml = xml.replace(/xmlns=\"http:\/\/www\.w3\.org\/2000\/svg\"/, '');
    // Rounded svg dimensions
    var width = Math.floor(svgElement.width());
    var height = Math.floor(svgElement.height());
    // Draw the SVG onto a canvas
    canvas.width = width;
    canvas.height = height;
    $(canvas).css('border', '2px solid red');
    canvg(canvas, xml, {
        ignoreDimensions: true,
        scaleWidth: width,
        scaleHeight: height
    });
    $('body').append(canvas); // When pointer enters the canvas it changes
    // I can copy the canvas and that copy won't change on pointer enter.
    $(this).hide();
}

小提琴

在Firefox 47和Chrome 49上验证的是MacOS X El Capitan (我的朋友也证实这是在火狐和Chrome上发生的)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-06 12:17:50

您必须使用ignoreMouse选项:

更新小提琴:http://jsfiddle.net/35t6fkvj/7/

代码语言:javascript
复制
canvg(canvas, xml, {
    ignoreDimensions: true,
    scaleWidth: width,
    scaleHeight: height,
    ignoreMouse: true
});

不知道为什么它认为应该添加一些鼠标事件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36450250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档