getBBox()对于rect或path不返回任何内容 [英] getBBox() returns nothing for rect or path

查看:144
本文介绍了getBBox()对于rect或path不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考下面的正确代码.

Please refer below rect code.

<rect id="container_svg_ChartArea" x="146.8" y="20" width="633.2" height="414" fill="White" stroke-width="1" stroke="Gray"></rect>

我尝试获取矩形边界框值,它不返回任何内容,即x = 0,y = 0,width = 0,height = 0时为"0"

i tried get the rectangle bounding box value it returns nothing i.e."0" for x=0,y=0,width=0,height=0

$("#container_svg_ChartArea")[0].getBBox()

但是当我获得x/y/width/height的属性时,它会返回一些值

but when i get the attribute for x/y/width/height it returns some value

$("#container_svg_ChartArea").attr("x") ->value returned.

与路径元素和矩形元素相同.

same for path element as well as rectangle element.

出了什么问题?

此处没有解决方案.

如何获取jQuery中svg路径的边界框或矩形(getBBox())

这就是为什么我创建了另一个线程.它不是重复的线程.

thats why i created another thread. it is not duplicate thread.

谢谢

Siva

推荐答案

看此示例,了解如何获取和管理svg元素的边框

Look this example on how to get and manage the bounding box of svg elements

http://www.janvas.com/illustrators_designers_developers/projects/janvas2D_web/examples_EN.php?exampleName = ufo_animation_EN

一般

var svgElement = document.getElementById('the id of your element');
bbox = svgElement.getBBox();

console.log( bbox.x ) ;
console.log( bbox.y ) ;
console.log( bbox.width ) ;   
console.log( bbox.height ) ; 

这篇关于getBBox()对于rect或path不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆