I am trying to figure out how this website here has made the responsive header image that fills the window size onload and resizes with the window resize while still filling the window in it's original ratio.
This is what I have come up with so far but it is very glitchy...
Working fiddle
$(window).load(function() {
$('#intro-background').height( $(window).height() );
$('#intro-background img').height( $(window).height() );
var imageRatio = (1900 / 1270); //Original image size
$(window).resize(function() {
$('#intro-background').height( $(window).height() );
var windowRatio = $(window).width() / $(window).height();
if(windowRatio != imageRatio) {
if($('#intro-background img').width() < $(window).width()) {
$('#intro-background img').width($(window).width());
$('#intro-background img').height($(window).width() / imageRatio);
} else if( $('#intro-background img').height() > $(window).height() ) {
$('#intro-background img').height($(window).height());
$('#intro-background img').width($(window).height() * imageRatio);
}
if($('#intro-background img').height() < $(window).height()) {
$('#intro-background img').height($(window).height());
$('#intro-background img').width($(window).height() * imageRatio);
}
}
});
});