Auto width and height for SVG image

前端 未结 3 408
南方客
南方客 2021-02-07 04:36

I am new to SVG, so sorry if this is a bit of a noob question. I am trying to figure out how to get an image to display with the full width and height of the refere

3条回答
  •  忘了有多久
    2021-02-07 05:24

    d3.select("svg")
      .append("image")
        .attr("id", "myImage")
        .attr("xlink:href", "myImage.png")
        .on("load", function(d) { 
            var myImage = new Image();
            myImage.onload = function() {
                d3.select("#myImage")
                    .attr("width", this.width)
                    .attr("height", this.height);
            }
            myImage.src = "myImage.png";
        });
    

提交回复
热议问题