2016-02-10 01:04:57 +01:00
|
|
|
|
|
|
|
//=include ../../../node_modules/is-in-viewport/lib/isInViewport.js
|
|
|
|
|
|
|
|
jQuery(function($) {
|
|
|
|
|
2016-02-15 19:34:10 +01:00
|
|
|
var wrigley = $('#wrigley'),
|
|
|
|
wrigleyArm = wrigley.find('#arm'),
|
|
|
|
wrigleyHead = wrigley.find('#head'),
|
|
|
|
wrigleyEye = wrigley.find('#eye');
|
2016-02-10 01:04:57 +01:00
|
|
|
|
2016-02-15 19:34:10 +01:00
|
|
|
var wrigleyAnimationStart = function() {
|
2016-02-11 16:45:32 +01:00
|
|
|
|
|
|
|
// set utility classes
|
2016-02-15 19:34:10 +01:00
|
|
|
if (wrigley.is( ':in-viewport( -180 )' ) ) {
|
|
|
|
wrigley.addClass('is-ready');
|
2016-02-11 16:45:32 +01:00
|
|
|
|
|
|
|
// toggle paused class so the :hover interaction can fire animation again
|
2016-02-15 19:34:10 +01:00
|
|
|
wrigleyArm.on('animationend webkitAnimationEnd oAnimationEnd', function(e) {
|
|
|
|
wrigleyArm.addClass('paused');
|
|
|
|
wrigleyHead.addClass('paused');
|
2016-02-11 16:45:32 +01:00
|
|
|
|
2016-02-15 19:34:10 +01:00
|
|
|
wrigley.on('mouseover', function() {
|
|
|
|
wrigleyArm.removeClass('paused');
|
|
|
|
wrigleyHead.removeClass('paused');
|
2016-02-11 16:45:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// fire eye blinking once other animations have finished
|
2016-02-15 19:34:10 +01:00
|
|
|
wrigleyEye.addClass('is-ready');
|
2016-02-11 16:45:32 +01:00
|
|
|
|
2016-02-15 19:34:10 +01:00
|
|
|
wrigleyEye.on('animationend webkitAnimationEnd oAnimationEnd', function(e) {
|
|
|
|
wrigleyEye.removeClass('is-ready');
|
2016-02-11 16:45:32 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
2016-02-15 19:34:10 +01:00
|
|
|
wrigley.removeClass('is-ready').removeClass('paused');
|
|
|
|
wrigleyArm.removeClass('paused');
|
|
|
|
wrigleyHead.removeClass('paused');
|
|
|
|
wrigleyEye.removeClass('is-ready').removeClass('paused');
|
2016-02-11 16:45:32 +01:00
|
|
|
}
|
2016-02-10 01:04:57 +01:00
|
|
|
}
|
|
|
|
|
2016-02-11 16:45:32 +01:00
|
|
|
// fire all the viewport things
|
2016-02-15 19:34:10 +01:00
|
|
|
wrigleyAnimationStart();
|
|
|
|
$(window).on('load resize scroll', wrigleyAnimationStart);
|
2016-02-11 16:45:32 +01:00
|
|
|
|
2016-02-10 01:04:57 +01:00
|
|
|
});
|