var pimgjq = $.noconflict(true); pimgjq(document).ready(function () { $(".tyimg").css("position", "relative"); var tyimgw = $(".tyimg").width(); //200 var tyimgh = $(".tyimg").height(); //400 $(".tyimg img").each(function () { $(this).css("position", "absolute"); var thisimgw = $(this).outerwidth(); //300 var thisimgh = $(this).outerheight(); //700 if ((thisimgh / thisimgw) > (tyimgh / tyimgw)) { $(this).width(parseint(thisimgw / thisimgh * tyimgh)); $(this).height(tyimgh); $(this).css("top", "0px"); $(this).css("left", parseint((tyimgw - thisimgw / thisimgh * tyimgh) / 2) + "px"); } else { $(this).width(tyimgw); $(this).height(parseint(thisimgh / thisimgw * tyimgw)); $(this).css("top", parseint((tyimgh - thisimgh / thisimgw * tyimgw) / 2) + "px"); $(this).css("left", "0px"); } }); });