FitImg makes fluid images more robust by allowing a minimum and maximum height. Use this plugin on your responsive design to clip ratio-based resizing of your images to fixed limits.
Here is a simple FitImg setup:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="jquery.fitimg.js"></script>
<script>
jQuery("#responsive_image").fitImg({
'minHeight:' 240,
'maxHeight:' 640
});
</script>
Your image should now fluidly resize, to cover the full width of it's container, while remaining at least 240px tall, and growing to taller than 640px;
Once your image hits the configured height limit, FitImg will align it within it's container element. You can align the image to the left, right or horizontal center of the container using the align
option.
jQuery("#responsive_image").fitImg({
'minHeight:' 240,
'maxHeight:' 640,
'align': 'right' // 'left' | 'right' | 'center'
});
By default align
is set to 'center'
.
- Make sure your container has a width!
display: inline
elements don't have a width. Usedisplay: block
ORdisplay: inline-block
+ a specified width (i.e.width: 100%
).position:absolute
elements need a specified width as well.
- Tweak until you like it.
- Set a No-JS fallback in your CSS.
v 1.0
- Initial Release
If you think you can make this better, please Download, Fork, & Commit. We'd love to see your ideas.