[solved][jquery] resizing images
EDIT: This issue is resolved.
I'm trying to resize the thumbnail images on a page proportionally using this jquery. For some reason though this code is not working. Why?:
Entire html markup is:
The css is:
Help is much appreciated.
EDIT: This issue is resolved.
I'm trying to resize the thumbnail images on a page proportionally using this jquery. For some reason though this code is not working. Why?:
Code:
$(document).ready(function() {
$("#gallery div.thumbnails img").load(function() {
$("#gallery div.thumbnails img").each(function() {
var width = $(this).width;
var height = $(this).height;
var max_width = $(this).css("max-width");
if (width > max_width) {
var ratio = width / height;
$(this).width(width);
$(this).height(max_width / ratio);
}
});
});
});
Entire html markup is:
Code:
<!DOCTYPE html>
<html>
<head>
<title>image gallery</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#gallery div.thumbnails img").load(function() {
$("#gallery div.thumbnails img").each(function() {
var width = $(this).width;
var height = $(this).height;
var max_width = $(this).css("max-width");
if (width > max_width) {
var ratio = width / height;
$(this).width(width);
$(this).height(max_width / ratio);
}
});
});
});
</script>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="gallery">
<ul class="slider_navigation">
<li><a href="#"><span><</span> Previous</a></li>
<li> | </li>
<li><a href="#">Next <span>></span></a></li>
</ul>
<div class="main_image">
<img src="#" alt="MainImg" />
</div>
<div class="thumbnails">
<img src="http://www.wjunction.com/images/cfg.png" alt="Image 1" />
<img src="http://www.wjunction.com/images/cleangui.png" alt="Image 2" />
<img src="http://www.wjunction.com/images/dislike.png" alt="Image 3" />
<img src="http://www.wjunction.com/images/like.png" alt="Image 4" />
<img src="http://www.wjunction.com/images/tempwatermark.png" alt="Image 5" />
</div>
</div> <!-- #gallery -->
</body>
</html>
The css is:
Code:
#gallery div.thumbnails img{
max-width:200px;
border:1px solid gray;
}
Help is much appreciated.
Last edited: