I am trying use jquery to set the height of an element to equal the users browser. Here is the code I got so far that\'s not working. Is it because I have a minimal height set
Try this, it keeps the image's aspect ratio
$(function(){
var ratio = $("img").width() / $("img").height();
var newWidth = ($(window).height()-10) * ratio;
if(newWidth > $(window).width())
$("img").css("width","100%");
else
$("img").css("width",newWidth+"px");
$(window).resize(function(){
var ratio = $("img").width() / $("img").height();
var newWidth = $(window).height() * ratio;
if(newWidth > $(window).width()){
$("img").css("width","100%");
}
else{
$("img").css("width",newWidth+"px");
}
});
});