【问题标题】:mouseenter / mouseleave event fired when moving from shape to circle in kinetic group在动力学组中从形状移动到圆形时触发 mouseenter / mouseleave 事件
【发布时间】:2014-04-03 03:53:38
【问题描述】:

我有包含自定义形状和圆形的 Kinetic 组。 Mouseenter 和 mouseleave 事件在 group 级别上指定。 当我从形状移动到圆形时,反之亦然,事件被触发,这(我猜)是不正确的,因为我一直在组之上。

  var stage = new Kinetic.Stage({
    container: 'container',
    width: 400,
    height: 300
  });
  var shapesLayer = new Kinetic.Layer();

  var group = new Kinetic.Group({
    x: 100,
    y: 40,
    listening: true
  });

      var square = new Kinetic.Shape({
         sceneFunc: function(context) {
           context.beginPath();
           context.moveTo(50, 50);
           context.lineTo(150, 50);
           context.lineTo(150, 100);
           context.lineTo(50, 100);
           context.lineTo(50, 50);
           context.closePath();
           // KineticJS specific context method
           context.fillStrokeShape(this);
         },
         fill: 'red',
         stroke: 'black',
         strokeWidth: 4
       });

      var circle =  new Kinetic.Circle();
        circle.x( 75 );
        circle.y( 75);
        circle.fill( 'LightGray' );
        circle.stroke( 'Gray' );
        circle.strokeWidth( 2 );
        circle.strokeEnabled( true );
        circle.listening(true);
        circle.draggable( true );
        circle.radius( 10 );

      group.add(square);
      group.add(circle);

  group.on( 'mouseenter', function( evt ) {         
        document.body.style.cursor = 'pointer';
    } );

  group.on( 'mouseleave', function( evt ) {         
        document.body.style.cursor = 'default';
    } );
  shapesLayer.add(group);
  stage.add(shapesLayer); `

在此处查看示例中的鼠标指针:http://jsfiddle.net/69K59/2/

【问题讨论】:

    标签: javascript html kineticjs


    【解决方案1】:

    组本身上的鼠标移动不会触发鼠标事件。

    节点(形状、圆形等)上的鼠标事件触发鼠标事件。

    这就是为什么你从圆圈移动到矩形时会得到离开+进入的原因。

    【讨论】:

    • 那为什么群上有监听参数呢?根据你所说,它没有真正的影响......
    • group.listening(false) 在使用一个命令关闭所有包含的节点的侦听时很有用。请记住 Kinetic.Groups 是容器的扩展,而不是节点的扩展。组允许在节点集上进行操作。 ;-)
    猜你喜欢
    • 1970-01-01
    • 2013-03-29
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2014-09-07
    相关资源
    最近更新 更多