我使用拉布来将一些SVG呈现到图像中。目前SVG到画布部分的工作还不错。但是,当指针进入画布时,我无法确定生成的画布为什么会发生变化。我真的需要复制生成的画布,还是我遗漏了什么?
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上发生的)。
发布于 2016-04-06 12:17:50
您必须使用ignoreMouse选项:
更新小提琴:http://jsfiddle.net/35t6fkvj/7/
canvg(canvas, xml, {
ignoreDimensions: true,
scaleWidth: width,
scaleHeight: height,
ignoreMouse: true
});不知道为什么它认为应该添加一些鼠标事件。
https://stackoverflow.com/questions/36450250
复制相似问题