Try This : jQuery image resize code(working with all browser)
/*
Here is Start Image Resize Code
*/
function image_resize() {
$("your-class-or-id img").each(function() {
/* Max width for the image */
var maxWidth = 230;
/* Max hieght for the image */
var maxHeight = 230;
/*Used for aspect ratio*/
var ratio = 0;
/*Current image width*/
var width = $(this).width();
/*Current image height */
var height = $(this).height();
/*Check if the current width is larger than the max*/
if (width > maxWidth) {
/*get ratio for scaling image*/
ratio = (maxWidth/width);
/* Set New hieght and width of Image*/
$(this).attr({
width : maxWidth,
height : (height * ratio),
alt : "your-alt-text-you-can-remove-this"
});
/* Reset height to match scaled image */
height = (height * ratio);
/* Reset width to match scaled image */
width = (width * ratio);
/*Check if current height is larger than max*/
if (height > maxHeight) {
/*get ratio for scaling image*/
ratio = (maxHeight/height);
/*Set new height and width*/
$(this).attr({
height : maxHeight,
width : (width * ratio),
alt : "your-alt-text-you-can-remove-this"
});
}
}
});
}
/*
Here is End Image Resize Code
*/
/*
How can we call this Function
*/
/* Start $(document).ready function() */
$(document).ready(function() {
/* Call Function For image Resize (Not for Webkit Browser) */
image_resize();
});
/* End $(document).ready function(*/
/* Call Function (for Webkit Browser like safari and Chrome) */
$(window).load(function() {
image_resize();
});
初始寬度的IMG不應該屬性包含除''%以外的單元 - 假定像素。 – prodigitalson 2010-05-31 19:32:51