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);
}
});