HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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())
            );
        }
    }

};