Skip to content

Instantly share code, notes, and snippets.

@tcha-tcho
Created May 7, 2013 18:20
Show Gist options
  • Save tcha-tcho/5534866 to your computer and use it in GitHub Desktop.
Save tcha-tcho/5534866 to your computer and use it in GitHub Desktop.
Fix ratio when using background images.
function fix_ratio(ele){
var img_ratio = 1.6;//ele.width()/ele.height(); 1920/1200
var window_ratio = $(window).width()/$(window).height();
if(img_ratio>window_ratio){
ele.css("height","100%").css("width","auto");
}else{
ele.css("width","100%").css("height","auto");
}
}
@tcha-tcho
Copy link
Author

use with this css

.bg {
  background-position: 50% 0% !important;
  width: auto;
  height: auto;
  position: fixed;
  max-width: none !important;
  top: 0;
  left: 0;
  z-index: 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment