Hi,
You can do it like this:
HTML Code:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Dynamically resize image</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
}
#container{
height: 100%;
width:300px;
overflow:hidden
}
</style>
</head>
<body>
<div id="container"><img src="contact.jpg" id="image"></div>
<script>
$(window).load(function() {
function resizeImage(){
img.css('height', el.height());
}
$(window).resize(function() {
resizeImage();
});
var el = $("#container");
var img = $("#image");
resizeImage();
});
</script>
</body>
</html>
Here's an example of what it looks like: http://hibbard.eu/blog/pages/dynamically-resize-image/
Whatever the viewport dimensions, the image will always scale to take up 100% of the available height (try resizing the window)
HTH
Edit: Oops! Ryan was faster and has a better solution. Note to self: Just because you can do it in jQuery, doesn't necessarily make it a good idea
Bookmarks