English 中文(简体)
如何获得特殊人群群体的高/宽度?
原标题:How does one get the height/width of an SVG group element?
  • 时间:2011-10-01 13:25:46
  •  标签:
  • svg

我需要了解特别志愿人员队伍的宽度和高度? 试图利用以下手段:

$( g#myGroup ).height()

......结果总是零?

问题回答

svg <g>ss. t 没有明确的身高和宽度,其体积与其中任何内容一致。 可以通过在以下要素上打上BBox来达到其实际高度/宽度:

var height = document.getElementById("myGroup").getBBox().height;

如果你真心 j忙,你可以写成

$( g#myGroup ).get(0).getBBox().height;

汇合公司

我拿到上述任何答案去做,但是,为了找到答案,我确实走过了这一解决办法:

var height = d3.select( #myGroup ).select( svg ).node().getBBox().height;
var width = d3.select( #myGroup ).select( svg ).node().getBBox().width;

这里将发现该组元素的实际宽度和高度。 简便。

根据上述答复,您可以设立“高等”职能。

/*
 * .widthSVG(className)
 * Get the current computed width for the first element in the set of matched SVG elements.
 */

$.fn.widthSVG = function(){
    return ($(this).get(0)) ? $(this).get(0).getBBox().width : null;
};

/*
 * .heightSVG(className)
 * Get the current computed height for the first element in the set of matched SVG elements.
 */
$.fn.heightSVG = function(){
    return ($(this).get(0)) ? $(this).get(0).getBBox().height : null;
};




相关问题
How to simplify SVG code?

Is it possible to simplify / clean up svg code by replacing the use-tags with standard svg elements? Maybe an inkscape plugin? Haven t found anything... Background: I m converting some svgs to javafx ...

How to link from SVG?

What I tried is this <a xlink:target="http://ponyoverflow.com"> <text class="text" x="20" y="718" text-anchor="start">Mail Order Ponies</text> </a> and variations with href ...

Ruby Support for SVG

Is there some library or helper to produce SVG graphics with Ruby? I googled a bit and found many, but all seem to be dusty and very incomplete… Does anyone know about some nice, reliable alternative?

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

热门标签