Created
August 25, 2012 10:01
-
-
Save muhittin/3463173 to your computer and use it in GitHub Desktop.
resize element to screen resolution (with jQuery)
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
function resize(oran){ | |
var newH = parseFloat( $(window).height() ); | |
var newW = parseFloat( $(window).width() ); | |
var rat = newW / newH; | |
if(rat > oran) | |
{ | |
var targetHeight = newH; | |
var targetWidth = newH * oran; | |
} | |
else | |
{ | |
var targetWidth = newW; | |
var targetHeight = newW / oran; | |
} | |
var targetTop = (newH - targetHeight) / 2; | |
var targetLeft = (newW - targetWidth) / 2; | |
return {width: targetWidth, height: targetHeigt, top: targetTop, left: targetLeft}; | |
} | |
// Usage: | |
var props = resize(4/3); | |
$("#myDiv").css(props); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment