0
// first case

$('canvas').drawRect({

  layer: true,

  data: { w: 300 },

  fillStyle: '#585',

  x: 100, y: 100,

  width: 100, height: 50

});

alert($('canvas').getLayer(0).data.w);

我可以从图层中获取数据。


// second case

$('canvas').drawRect({

  layer: true,

  data: { w: 300 },

  fillStyle: '#585',

  x: 100, y: 100,

  width: $('canvas').getLayer(0).data.w, height: 50

});

我无法在图层本身中获取数据。

4

2 回答 2

0

之前可以使用 GetLayer() 吗?将其分配给变量,然后将其放回原处?

但是,如果您从 jCanvas 外部跟踪它,正如我理解 jCanvas 的目的,您不应该担心 jCanvas 的外部数据。而是动态抓取图层属性并进行调整。

我的项目也有同样的问题。

于 2014-10-16T05:05:17.960 回答
0

一个简单实用的解决方案是预先指定您的数据对象,以便在您的drawRect()调用范围内可以访问它:

var rectData = { w: 300 };

$('canvas').drawRect({

  layer: true,

  data: rectData,

  fillStyle: '#585',

  x: 100, y: 100,

  width: rectData.w, height: 50

});
于 2014-10-10T00:39:37.190 回答