Ok so I've got this code here (which is working and all) but it feels... bloated ?
I was wondering if maybe I missed something I cannot see anymore to make it better:
var chestTween = [];
var delays = [];
for (var i = 0; i < 9; i++) {
delays.push(4 + i * .2);
}
delays = shuffle(delays);
$(".chest").each(function(i, e) {
var $this = this;
var randX = parseInt(Math.floor(Math.random() * 200 + 1)),
randY = parseInt(Math.floor(Math.random() * 200 + 1)),
randXS = Math.floor(Math.random() * 2) ? "+=" : "-=",
randYS = Math.floor(Math.random() * 2) ? "+=" : "-=",
randRot = -Math.floor(Math.random() * (5 - 1 + 1) + 1),
randRotE = Math.floor(Math.random() * (5 - 1 + 1) + 1);
TweenMax.from(
$this,
1,
{
x: randXS + randX,
y: randYS + randY,
delay: delays[i],
ease: Power4.easeOut
}
);
TweenMax.fromTo(
$this,
1,
{
rotation: -360,
scale: 0
},
{
rotation: randRot,
scale: 1,
ease: Power4.easeOut,
delay: delays[i],
onComplete: function() {
// Pushing those in an array because I need to kill them individually later
chestTween.push(TweenMax.to($this, 2, { rotation: randRotE, yoyo: true, repeat: -1, ease: Power1.easeInOut }));
}
}
);
});
The result is this (seems laggy, but it's just because of the recording software): https://imgur.com/ePq3fIx
Lyn.