拉斐尔对象宽度

Raphael Object Width

本文关键字:对象      更新时间:2023-09-26

好的,我需要一些帮助来尝试访问Raphael对象的宽度。这是我做的小提琴的链接。

Fiddle

它一直返回undefined,但对象已定义。有点困惑为什么我不能按照我想要的方式访问它。

提前感谢!

如果你做console.log(circle);,你会看到它们在圆上没有width属性,所以这就是为什么它是undefined。另一件事,我真的不认为你能得到圆的宽度,你能得到的是半径,试着使用:

​console.log(circle.paper.width); // prints the "canvas" width
console.log(circle.attrs.r);     // prints the circle radius, circle.attrs.r * 2 you get
                                 // the width of the circle

您可能需要circle.getBBox(),它将返回以下内容:

x:top left corner x
y:top left corner y
x2:bottom right corner x
y2:bottom right corner y
width:width
height:height 

它可能会返回一个不是整数的答案。