Canvg - canvas 鼠标移动时的变化

Canvg - canvas changes on mousemove

我正在使用 canvg 将一些 SVG 渲染成图像。目前 SVG 到 canvas 部分工作正常。但是我无法确定为什么当指针进入时生成的 canvas 会发生变化。我真的必须复制生成的 canvas,还是我遗漏了什么?

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();
}

jsfiddle

在 Firefox DE 47 和 MacOS X El Capitan 下的 Chrome 49 上验证(我的朋友也验证了这在 Firefox 和 Chrome 上的 Windows 下发生)。

您必须使用 ignoreMouse 选项:

已更新 fiddle:http://jsfiddle.net/35t6fkvj/7/

canvg(canvas, xml, {
    ignoreDimensions: true,
    scaleWidth: width,
    scaleHeight: height,
    ignoreMouse: true
});

不确定为什么它认为应该添加一些鼠标事件