gpt4 book ai didi

javascript - Canvg - Canvas 在鼠标移动时发生变化

转载 作者:行者123 更新时间:2023-11-30 16:09:45 26 4
gpt4 key购买 nike

我正在使用 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

在 MacOS X El Capitan 下的 Firefox DE 47 和 Chrome 49 上验证(我的 friend 也验证了在 Windows 下的 Firefox 和 Chrome 上都发生了这种情况)。

最佳答案

您必须使用 ignoreMouse选项:

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

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

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

关于javascript - Canvg - Canvas 在鼠标移动时发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36450250/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com