我正试图在kineticjs中获得节点形状的宽度。 我这样做:
var node = left.find('Rect');
var width = node.width()
console.log(width);
,left是一个具有Rect的组。
var shape = new Kinetic.Rect({
x: 0,
y: 0,
width: C_EC_WIDTH,
height: C_EC_WIDTH,
fill: viewcolor,
stroke: "black",
strokeWidth: 1
});
left.add(shape);
但我总是得到这个结果:
我尝试过getWidth(),setWidth(100),width()和width(100)。宽度(100)和setWidth(100)正常工作。但其他人没有!我无法访问形状的宽度,我总是得到对象!
我做错了什么?
修改
试过这个:
var width = node.width().width().width();
并得到相同的结果。它返回动能对象!我不知道为什么!这对我没有任何意义。
答案 0 :(得分:1)
find()
函数返回对象集合。容器中可能有许多矩形。
所以应该这样做:
var node = left.find('Rect')[0];
var width = node.width()
console.log(width);