【问题标题】:Get the width of a rect shape获取矩形的宽度
【发布时间】:2014-10-13 16:28:55
【问题描述】:

我正在尝试在 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)。 width(100) 和 setWidth(100) 工作正常。但其他人没有!我无法获得形状的宽度,我总是得到对象!

我做错了什么?

编辑:

试过这个:

var width = node.width().width().width();

并得到相同的结果。它返回动力学对象!我不知道为什么!这对我来说没有任何意义。

【问题讨论】:

    标签: javascript kineticjs


    【解决方案1】:

    find() 函数返回对象集合。容器中可能有许多矩形。 所以应该这样做:

      var node = left.find('Rect')[0];
      var width = node.width()
      console.log(width);
    

    【讨论】:

    • 非常感谢!我不记得了。
    • 你知道kineticjs官方页面的教程链接是怎么回事吗? html5canvastutorials.com/kineticjs/…
    • 坏了。看来mainteiner没时间修了。使用存档:web.archive.org/web/20140410105707/http://…
    • 谢谢@lavrton。我已经使用了你发给我的链接。我注意到几个月前,自从网站更新后,我发现问题没有解决很奇怪。但是,是的,我知道他们没有时间这样做。 Kineticjs 很棒,祝贺你所做的工作:)
    猜你喜欢
    • 2021-06-20
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    • 2021-01-10
    • 2017-03-15
    • 2021-08-27
    • 2016-09-29
    • 1970-01-01
    相关资源
    最近更新 更多