|
function Button(id) { |
|
|
|
var self = this; |
|
this.el = document.getElementById(id); |
|
|
|
// state variables |
|
this.state = 1; |
|
this.totalStates = 5; |
|
this.states = {}; |
|
|
|
// animation settings |
|
this.anim = { |
|
time: 0.75, |
|
bounce: Back.easeOut.config(1.4), |
|
out: Power2.easeOut |
|
}; |
|
|
|
// state initialization |
|
this.setupStates = function() { |
|
|
|
// |
|
// empty states |
|
// |
|
|
|
self.states = []; |
|
|
|
// |
|
// scale small |
|
// |
|
|
|
self.states.push( |
|
TweenMax.to(self.el, self.anim.time, { |
|
scale: 0.7, |
|
ease: self.anim.bounce, |
|
paused: true |
|
}) |
|
); |
|
|
|
// |
|
// scale full |
|
// |
|
|
|
self.states.push( |
|
TweenMax.to(self.el, self.anim.time, { |
|
scale: 1, |
|
ease: self.anim.bounce, |
|
paused: true |
|
}) |
|
); |
|
|
|
// |
|
// rotation dance |
|
// |
|
|
|
self.states.push( |
|
TweenMax.to(self.el, self.anim.time, { |
|
rotation: 15, |
|
ease: self.anim.out, |
|
onComplete: function () { |
|
TweenMax.to(self.el, self.anim.time, { |
|
rotation: -15, |
|
ease: self.anim.out, |
|
onComplete: function () { |
|
TweenMax.to(self.el, self.anim.time, { |
|
rotation: 0, |
|
ease: self.anim.bounce |
|
}); |
|
} |
|
}); |
|
}, |
|
paused: true |
|
}) |
|
); |
|
|
|
// |
|
// shadow |
|
// |
|
|
|
var baseShadow = "0px 4px 0px 0px #F9A485", |
|
bigShadowDown = [ |
|
"0px 4px 0px 0px #F9A485", |
|
"0px 8px 0px 0px #B7D6D0", |
|
"0px 12px 0px 0px #68AEA1" |
|
].join(","), |
|
bigShadowUp = [ |
|
"0px -4px 0px 0px #F9A485", |
|
"0px -8px 0px 0px #B7D6D0", |
|
"0px -12px 0px 0px #68AEA1" |
|
].join(","); |
|
|
|
self.states.push( |
|
TweenMax.to(self.el, self.anim.time, { |
|
boxShadow: bigShadowDown, |
|
ease: self.anim.out, |
|
onComplete: function () { |
|
TweenMax.to(self.el, self.anim.time, { |
|
boxShadow: bigShadowUp, |
|
ease: self.anim.out, |
|
onComplete: function () { |
|
TweenMax.to(self.el, self.anim.time, { |
|
boxShadow: baseShadow, |
|
ease: self.anim.out |
|
}); |
|
} |
|
}); |
|
}, |
|
paused: true |
|
}) |
|
); |
|
|
|
// |
|
// border radius |
|
// |
|
|
|
self.states.push( |
|
TweenMax.to(self.el, self.anim.time, { |
|
borderRadius: "1em", |
|
ease: self.anim.out, |
|
onComplete: function () { |
|
TweenMax.to(self.el, self.anim.time, { |
|
borderRadius: "0.125em", |
|
ease: self.anim.out |
|
}); |
|
}, |
|
paused: true |
|
}) |
|
); |
|
} |
|
|
|
// initialize the button |
|
this.init = function() { |
|
self.setupStates(); |
|
self.stateHandler(); |
|
self.el.addEventListener("click", self.stateHandler); |
|
}; |
|
|
|
// triggering different states |
|
this.stateHandler = function() { |
|
self.states[self.state - 1].restart(); |
|
// setup states to reset |
|
self.setupStates(); |
|
// loop to next state |
|
if (self.state < self.totalStates) { self.state++ } else { self.state = 1 }; |
|
}; |
|
|
|
} |
|
|
|
// my first GSAP button |
|
var button = new Button("btn"); |
|
// get goin, son. |
|
button.init(); |
|
|
|
|
|
|
|
jakealbaughSignature(); |