jQuery plugin to fit images while keeping the width/height ratio
Latest commit 37f923f Feb 5, 2013 @miyagawa Merge pull request #1 from dongriab/master
reset when replace the img@src
Failed to load latest commit information.
README oops, typo Mar 16, 2009
jquery.fitimage.js reset when replace the img@src Feb 5, 2013
sample.html Initial import Mar 16, 2009
spacer.gif Initial import Mar 16, 2009


jquery.fitimage - jQuery plugin to fit images

You're loading images with unknown width and height, but don't want to
stretch the images with wrong aspect ratio. This plugin swaps the
images with a placeholder to load, preloads the actual image in the
background, calculate the size and assign proper margins to fit the
image with given width and height.


  <script src="jquery.fitimage.js"></script>
    $('.fit').fitimage({ placeholder: "/uri/to/placeholder.png" });
  <div class="container">
    <img src="http://example.com/test.jpg" class="fit" style="width:200px;height:200px" />

For example, if test.jpg's size is 800x600, fitimage() will update the
CSS property of the given img element:


See sample.html for more.