diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/api/svggraphicselement/getbbox | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/web/api/svggraphicselement/getbbox')
-rw-r--r-- | files/ja/web/api/svggraphicselement/getbbox/index.html | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/files/ja/web/api/svggraphicselement/getbbox/index.html b/files/ja/web/api/svggraphicselement/getbbox/index.html new file mode 100644 index 0000000000..68e2885a79 --- /dev/null +++ b/files/ja/web/api/svggraphicselement/getbbox/index.html @@ -0,0 +1,89 @@ +--- +title: getBBox() +slug: Web/API/SVGGraphicsElement/getBBox +tags: + - API + - Method + - Reference + - SVG + - SVG DOM + - SVGGraphicsElement + - メソッド +translation_of: Web/API/SVGGraphicsElement/getBBox +--- +<div>{{APIRef}}</div> + +<p><code><strong>SVGGraphicsElement.getBBox()</strong></code> で、オブジェクトが収まる最小の矩形の座標を特定することができます。返される座標は、現在の SVG 空間、すなわち対象の要素に含まれる位置に関する属性すべてを適用した後の空間に従います。</p> + +<p>メモ: <code>getBBox</code> は要素がまだレンダリングされていない場合でも、メソッドが呼び出されたときに実際の境界ボックスを返します。また、要素またはその親に適用される変換は無視します。</p> + +<div class="blockIndicator note"> +<p><code>getBBox</code> は {{domxref("Element.getBoundingClientRect()", "getBoundingClientRect()")}} とは異なる値を返します。後者はビューポートからの相対値を返します。</p> +</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox">let bboxRect = object.getBBox();</pre> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>返値は {{domxref("SVGRect")}} オブジェクトで、境界ボックスを定義します。この値はその要素や親要素に適用された変形属性を無視したものです。</p> + +<h2 id="Example" name="Example">例</h2> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"><svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"> + <g id="group_text_1"> + <text x="5" y="16" transform="scale(2, 2)">Hello World!</text> + <text x="8" y="32" transform="translate(0 20) scale(1.25 1)">Hello World Again!</text> + </g> + <!-- Shows BBox in green --> + <rect id="rect_1" stroke="#00ff00" stroke-width="3" fill="none"> </rect> + <!-- Shows BoundingClientRect in red --> + <rect id="rect_2" stroke="#ff0000" stroke-width="3" fill="none"></rect> +</svg> +</pre> + +<h3 id="JavaScript" name="JavaScript">JavaScript</h3> + +<pre class="brush: js">var rectBBox = document.querySelector('#rect_1'); +var rectBoundingClientRect = document.querySelector('#rect_2'); +var groupElement = document.querySelector('#group_text_1'); + +var bboxGroup = groupElement.getBBox(); +rectBBox.setAttribute('x', bboxGroup.x); +rectBBox.setAttribute('y', bboxGroup.y); +rectBBox.setAttribute('width', bboxGroup.width); +rectBBox.setAttribute('height', bboxGroup.height); + +var boundingClientRectGroup = groupElement.getBoundingClientRect(); +rectBoundingClientRect.setAttribute('x', boundingClientRectGroup.x); +rectBoundingClientRect.setAttribute('y', boundingClientRectGroup.y); +rectBoundingClientRect.setAttribute('width', boundingClientRectGroup.width); +rectBoundingClientRect.setAttribute('height', boundingClientRectGroup.height);</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('SVG1.1', 'types.html#__svg__SVGLocatable__getBBox', 'getBBox')}}</td> + <td>{{Spec2('SVG1.1')}}</td> + <td>初回定義 (SVG 要素のみに適用).</td> + </tr> + </tbody> +</table> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="https://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#getBBox">getBBox in SVG Primer</a></li> +</ul> |