juliangarnier / anime

JavaScript animation engine
https://animejs.com
MIT License
50.31k stars 3.68k forks source link

Negative delay forces previous animation to reach its final position before it should #464

Closed alvarotrigo closed 5 years ago

alvarotrigo commented 5 years ago

Describe the bug When using a negative delay in one animaiton, the previous on gets to the final position before before reaching the duration.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://jsfiddle.net/alvarotrigo/6yev2wc0/15/
  2. Click on the button 'Click'
  3. See error

Expected behavior Animation to stop at whatever position it is before another one gets applied to the same element.

Desktop (please complete the following information): Any device and OS

With Anime.js https://jsfiddle.net/alvarotrigo/6yev2wc0/15/

With Tweenlite: https://jsfiddle.net/alvarotrigo/6yev2wc0/18/

Code for the reproduction:


$('button').click(function() {
  var tl = anime.timeline({
      targets: '#path',
        duration: 500,
        direction: 'normal',
      duration: 1000,
      easing: 'easeInOutQuad',
    });

    tl.add({
        d: 'M0 100 L 300 0 L 300 300.4 L 0 300 Z',
    });

     tl.add({
        d: 'M50 50 L 300 0 L 300 300.4 L 0 300 Z',
        delay: -800
    });
});
alvarotrigo commented 5 years ago

My bad. I fixed it using the offset parameter with a negative value.

https://jsfiddle.net/alvarotrigo/6yev2wc0/28/

     tl.add({
        d: 'M50 50 L 300 0 L 300 300.4 L 0 300 Z',
    }, '-=700');