Applied tween inside each(), how do I use reverse()?

走远了吗. 提交于 2019-12-14 04:06:21

问题


Let's suppose I apply a tween to each element on my canvas

elements.each(function (element) {
    new Kinetic.Tween({
        node: element,
        rotationDeg: 180
    }).play();
});

All items have been tweened and have passed from their original state to a final state. My question is: How would I apply a reverse() to revert each item to their original state?


回答1:


Store the tweens inside an array, and then loop through that array and use .reverse()

    elements = stage.get('Rect');
    var tweenArray = [];

    // reverse tween
    document.getElementById('reverse').addEventListener('click', function () {
        for (var i=0; i<tweenArray.length; i++) {
            tweenArray[i].reverse();
        }
    }, false);

    // play tween forward
    document.getElementById('play').addEventListener('click', function () {
        elements.each(function (element) {
            var tween = new Kinetic.Tween({
                node: element,
                rotationDeg: 180
            }).play();
            tweenArray.push(tween);
        });
    }, false);

jsfiddle



来源:https://stackoverflow.com/questions/17931871/applied-tween-inside-each-how-do-i-use-reverse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!