Search code examples
html5-canvaskineticjs

Tween after dragging doesn't start to the drag-end position (with KineticJS)


This looks maybe like a bug, don't know if it's really one.

»» http://jsbin.com/ejizib/3/edit

After you move the gray rectangle, there is a tween that changes its position. But the tween starts with the origin position, not the last "drag-end" position.

The tween should start with the drag-end position and go until the x. parameter. Why doesn't it work on my jsbin?


Solution

  • I got it to work by instantiating the tween inside 'dragend' and removing tween.reset();

    rect.on('dragend', function() {
      var tween = new Kinetic.Tween({
        node: rect, 
        duration: 2,
        x: lenght/2
      });
      tween.play();
    });
    

    http://jsbin.com/ivobup/3/edit