问题
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