动态js旋转到鼠标,点击阶段

时间:2013-06-14 22:07:54

标签: rotation mouse kineticjs stage

触发鼠标位置事件时出现问题。当我拖动它时,对象正在移动,但是当我点击舞台时却没有。我该怎么办? (当然我正在添加一个舞台和图层和东西;)非常感谢提前!

function rotateAlltoMouse(layer3) {

      for(var n = 0; n < layer3.getChildren().length; n++) {
      var shape = layer3.getChildren()[n];
      var stage = shape.getStage();
      var mousePos = stage.getMousePosition();



      var xd =  shape.getPosition().x - mousePos.x;
      var yd =  shape.getPosition().y - mousePos.y ;
       var theta = Math.atan2(yd, xd);
      var degree = theta / (Math.PI / 180) - 45;

      shape.setRotationDeg(degree);

    }
  }
     $('#container').bind('mousemove touchstart', function() {
                               rotateAlltoMouse(layer3);
                             });                         

1 个答案:

答案 0 :(得分:0)

只是一个猜测---如果你提供更多代码,可能比猜测更好;)

尝试使用kineticJS请求包含DOM元素,以便您知道正在获得正确的容器。 KineticJS为自己的使用创建了一些支持元素,而#container可能无法进入舞台。

$(stage.getDOM()).on('mousemove',  function(){ rotateAlltoMouse(layer3); });