Skip to content Skip to sidebar Skip to footer

Applied Tween Inside Each(), How Do I Use Reverse()?

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();

Solution 1:

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

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

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

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

jsfiddle

Post a Comment for "Applied Tween Inside Each(), How Do I Use Reverse()?"