<Bodystyle= "Text-align:center;"><DivID= "TestID"style= "background:red; Margin-right:auto; Margin-left:auto; width:173;height:184 "> <imgsrc= "Http://e.hiphotos.baidu.com/image/pic/item/024f78f0f736afc385a0f0e7b119ebc4b6451280.jpg"style= "Display:none;"></Div><Body><Scriptsrc= "Http://code.jquery.com/jquery-latest.js"></Script><Script> varselector= $("#testID"). Find ("img"); //Selector Selectorselector.hide (); varcontainerwidth= 173 * 1; //173: Container width 1: width padding 100% varContainerheight= 184 * 0.9; //184: Container height 0.9: Height fill 90% //when all the pictures are loaded and then dynamically calculate the height of the picture to adjustwindow.onload=Dynamicsetimagewithheight; //dynamically adjust the width and height function functiondynamicsetimagewithheight () {Selector.each (function () { varwidth= $( This). width (); varHeight= $( This). Height (); if(Width>containerwidth) {Height=Height*containerwidth/width; Width=containerwidth; } if(Height>containerheight) {Width=width*Containerheight/height; Height=Containerheight; } width=parseint (width); Height=parseint (height); $( This). css ({width:width.toString ()+ "px", height:height.toString ()+ "px" }); }); Selector.fadein (); };</Script>