Skip to content

Instantly share code, notes, and snippets.

@bbbrrriiiaaannn
Created March 23, 2012 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbbrrriiiaaannn/2176356 to your computer and use it in GitHub Desktop.
Save bbbrrriiiaaannn/2176356 to your computer and use it in GitHub Desktop.
Lazy pre-Backstretch Backstretch
$(window).resize(function(evt){
var imgDim = [ $("img#homepage-image").width(), $("img#homepage-image").height() ];
var bodyDim = [ $(document.body).width(), $(document.body).height() ];
$("#homepage-image-wrapper").width(bodyDim[0]).height(bodyDim[1]);
var widthRatio = imgDim[0]/bodyDim[0];
var heightRatio = imgDim[1]/bodyDim[1];
if( widthRatio > heightRatio ) {
$("img#homepage-image").height(bodyDim[1]).width(imgDim[0]/heightRatio);
} else {
$("img#homepage-image").width(bodyDim[0]).height(imgDim[1]/widthRatio);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment