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/topswtwmobile.komma.pro/wwwroot/js/app/modules/imageFitter.js
define([],function()
{
    $(function(){

        $('img.fit').one('load',function(){
            fitImage($(this));
        }).each(function(){
            if(this.complete) $(this).load();
        });


        var timeout;
        $(window).resize(function() {
            clearTimeout(timeout);
            timeout = setTimeout(doneResizing, 500);
        });

        function doneResizing(){
            $('img.fit').each(function(){
                fitImage($(this));
            });
        }


    });

    function fitImage($t)
    {
        var parent = { width : $t.parent().width(), height : $t.parent().height() };
        var image = { width : $t.width(), height : $t.height() }; 
        var ratio = image.width / image.height;
        var w, h;

        if(ratio > 1)
        {
            // Landscape
            w = parent.width;
            h = w / ratio;

            if(h > parent.height)
            {
                h = parent.height;
                w = h * ratio;
            }
        }
        else
        {
            // Portrait
            h = parent.height;
            w = h * ratio;
        }

        $t.css({
            width: w+'px',
            height: h+'px',
            marginLeft: (w / -2)+'px',
            marginTop: (h / -2)+'px'
        });
        $t.animate({ opacity: 1},300);
    }
});