2013-02-28 27 views
0

我在这一层有一个可拖动的图层和一个大的透明背景。我想在用户点击的位置准确添加文本。当我没有拖动图层时,一切正常,但是当我拖动它时,文本将添加到我不想要的地方。因为event.x和event.y不是点击区域的形状的x和y。坐标必须转换。但我不知道如何获得转换矢量。如何获取点击形状的位置(KineticJS)

plot = {}; 
    plot.stage = new Kinetic.Stage({width: 500, height:500, 
     container: 'abc', 
     'draggable': true}); 
    plot.layer = new Kinetic.Layer(); 
    plot.stage.add(plot.layer); 
    plot.background = new Kinetic.Rect({ 
      x: -1000, 
      y: -1000, 
      width: 2000, 
      height: 2000, 
      fill: "#000000", 
      opacity: 0.05, 
      type: 'blank' 
    }); 
    plot.layer.add(plot.background); 

    plot.background.on('click', function(e) { 
     e.x; 
     e.y; 
     // e.x and e.y are not true after dragging stage 
    }); 
+0

这是可能的,但不知道你做了什么。代码plz – allenhwkim 2013-02-28 14:55:59

回答

1

当使用KineticJS时,您希望避免event.x和event.y,因为KineticJS已经有获取位置的方法。

var position = stage.getUserPosition(); // this returns an object like {x: 100, y: 140} 

另外,请检查您将文本添加到哪个图层。另外,请显示一些代码。

0

你需要绝对地设置元素的位置。使用这个:

plot.setAbsolutePosition(stage.getUserPosition());