简体   繁体   中英

Canvg - canvas changes on mousemove

I am using canvg in order to render some SVG into an image. Currently SVG to canvas part is working just fine. However I am unable to determine why the generated canvas changes when a pointer enters it. Do I really have to copy the generated canvas, or am I missing something?

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

Verified on Firefox DE 47 and Chrome 49 under MacOS X El Capitan (also my friend verified that this is happening under Windows on both Firefox and Chrome).

You have to use the ignoreMouse option :

updated fiddle : http://jsfiddle.net/35t6fkvj/7/

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

Not sure why it thinks it should add some mouse events though

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM