Created
May 8, 2010 12:57
-
-
Save madmax/394550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ImageResize = { | |
margin: 8, | |
parse: function(css_id, margin) { | |
if(margin) { this.margin = margin; } | |
$$('#' + css_id + ' img').each(function(img) { | |
this.resize(img, $(css_id).getWidth() - this.margin); | |
}, this); | |
}, | |
resize: function(img, max_width) { | |
// if image is bigger that max_width we add them width = max_width and don't check image again | |
if (img.width > max_width) { | |
img.style.width = max_width + 'px'; | |
return true; | |
} | |
// if image isn't complete loaded just bind to check size again after 5 ms | |
if (!img.complete) { | |
setTimeout(function() { | |
ImageResize.resize(img, max_width); | |
}, 5); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment