File: D:/HostingSpaces/SBogers10/douven.komma.pro/resources/assets/js/site/animationHandler.js
/* ==========================================================================
Animation Handler
========================================================================== */
//TODO Test of this works
var AnimationHandler = {
fullElementQuery : '.animation',
partialElementQuery : '.animation-part',
init : function()
{
setTimeout(function(){ AnimationHandler.viewportChange() }, 800);
// Detect if throttle and debounce function are init
if (typeof $.throttle === "undefined") rebindThrottleDebounce();
$(window).scroll(
$.throttle( 250, AnimationHandler.viewportChange() )
);
},
viewportChange: function () {
$(AnimationHandler.partialElementQuery).each(function(){
AnimationHandler.detectPartialInViewport( $(this) );
});
$(AnimationHandler.fullElementQuery).each(function(){
AnimationHandler.detectFullInViewport( $(this) );
});
},
detectPartialInViewport : function(els)
{
if(els.length > 0) {
//special bonus for those using jQuery
if (typeof jQuery !== 'undefined' && els instanceof jQuery) els = els[0];
var rect = els.getBoundingClientRect();
// DOMRect { x: 8, y: 8, width: 100, height: 100, top: 8, right: 108, bottom: 108, left: 8 }
var windowHeight = (window.innerHeight || document.documentElement.clientHeight);
var windowWidth = (window.innerWidth || document.documentElement.clientWidth);
var vertInView = (rect.top <= (windowHeight - margin)) && ((rect.top + rect.height) >= 0);
var horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0);
return (vertInView && horInView);
}
},
detectFullInViewport : function(els)
{
if(els.length > 0){
if (typeof jQuery === "function" && els instanceof jQuery) {
els = els[0];
}
var rect = els.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.bottom <= (window.innerHeight || $(window).height())
);
}
}
};