Created
February 19, 2011 23:45
-
-
Save stresslimit/835514 to your computer and use it in GitHub Desktop.
jquery bg image resizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(resizebg); | |
$(window).resize(resizebg); | |
function resizebg() { | |
var w,h,x,y; | |
var ratio = 4/3; | |
x = $(window).width(); | |
y = $(window).height(); | |
var constrain = x/y > ratio ? 'w' : 'h'; | |
if(constrain=='w') { | |
w = x; | |
h = Math.round(x*.75); | |
} else if(constrain=='h') { | |
w = Math.round(y*1.333); | |
h = y; | |
} | |
$('#bg').css({ 'width': w+'px', 'height': h+'px'}); | |
} | |
</script> | |
<style> | |
#bg { position:absolute; bottom:0; right:0; z-index:0; } | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment