Anime: Reverse callback?

Created on 15 Aug 2017  路  5Comments  路  Source: juliangarnier/anime

I'm playing an animation, but on complete: I change a few hidden css properties (irreversibly), and I'd really much like to find a way to "undo" them because obviously, they do not change back when the animation is reversed.. Any ideas?

All 5 comments

I had the same problem as you. You just need to trigger the animation and the function you desire with some js event (in my case). If you insert the code you want to run after the .reverse(); it should be ejecuted after it.

This is the code I used:

        function somefunction(){
            $("#target").css("pointer-events","all"); //SETTING PROPIERTY ON
            var relativeOffset = anime.timeline();
                relativeOffset
                    .add({
                        //ANIMATION
                    });

            //REVERSE
            document.querySelector('#somebutton').onclick = function() {
                relativeOffset.play();
                relativeOffset.reverse();
                $("#target").css("pointer-events","none"); //SETTING PROPIERTY OFF
            }
        }

Hope it helps.

for the time being i think this little hack will work:

    myTimeline.completed = false;
    myTimeline.complete = () => { 
        // your call back funtion
        console.log("reverse done 馃槒");
    };
    myTimeline.reverse();
    myTimeline.play();

Perfect. Thank you guys.

Dunno about you guys, but in 2.2.0 I had to do more than completed=false. These are all required changes for the begin and/or complete timeline callbacks to be called.

timeline.began=timeline.completed=false;
timeline.loop=timeline.progress=0;
timeline.reverse();

timeline.begin = _ => console.log('> new begin callback');
timeline.complete = _ => console.log('> new complete callback');

timeline.play();

I'm testing this solution

  • get seek value
  • pause timeline
  • create a new timeline
  • set the seek value
  • reverse timeline
  • play timeline
Was this page helpful?
0 / 5 - 0 ratings

Related issues

trusktr picture trusktr  路  6Comments

tom2strobl picture tom2strobl  路  4Comments

KEYHAN-A picture KEYHAN-A  路  3Comments

dpw1 picture dpw1  路  4Comments

darkylmnx picture darkylmnx  路  7Comments