[英]Get the bounding box of a selected SVG element
如果您有對DOM節點的引用,請使用
svgNode.getBoundingClientRect()
https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect
編輯:SVG Edit有一個返回當前所選元素的方法:
svgCanvas.getSelectedElems()
所以在上面的例子中:
svgNode = svgCanvas.getSelectedElems()[0];
svgNode.getBoundingClientRect();
有關示例和答案,請參閱http://granite.sru.edu/~ddailey/svg/BBox0M.svg 。
簡而言之,此代碼適用於Chrome:
<script>
function foo(evt)
{
console.log(evt.target.getBBox());
}
</script>
<svg>
<circle onclick="foo(evt)" r="20%" cx="50%" cy="50%"/>
</svg>
我不確定我是否正確理解你,但是如果你想獲得jQuery元素的高度或寬度,請使用width()和height():
log("The svg is " + $("img").width() + "px wide.");
log("The svg is " + $("img").height() + "px tall.");
JSFiddle示例: http : //jsfiddle.net/gGWU4/
假設你有元素的句柄,我會認為這會起作用,不是嗎?
box = svgedit.utilities.getBBox(selected);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.