function drawimage(imgd,fitwidth,fitheight){ var image=new image(); image.src=imgd.src; var fwidth = fitwidth; var fheight = fitheight; if(image.width>0 && image.height>0){ /*if((image.height * 1.8) < image.width){ fitheight = fitheight * 2.3 * (image.height / image.width); if(fitheight > fheight){ fitheight = fheight; } } if((image.width * 1.8) < image.height){ fitwidth = fitwidth * 2.3 * (image.width / image.height); if(fitwidth > fwidth){ fitwidth = fwidth; } }*/ if(image.width/image.height <= fitwidth/fitheight){ if(image.width>fitwidth){ imgd.width=fitwidth; imgd.height=(image.height*fitwidth)/image.width; }else{ imgd.width=image.width; imgd.height=image.height; } } else{ if(image.height>fitheight){ imgd.height=fitheight; imgd.width=(image.width*fitheight)/image.height; }else{ imgd.width=image.width; imgd.height=image.height; } } if($(imgd).width() != fwidth){ $left = - ($(imgd).width() - fitwidth) / 2; $left = $left + 'px'; imgd.style.marginleft = $left; } if($(imgd).height() != fheight){ $height = - ( $(imgd).height() - fitheight) / 2; $height = $height + 'px'; imgd.style.margintop = $height; } } } function drawimage2(imgd,fitwidth,fitheight){ var image=new image(); image.src=imgd.src; if(image.width>0 && image.height>0){ if(image.width/image.height>= fitwidth/fitheight){ if(image.width>fitwidth){ imgd.width=fitwidth; imgd.height=(image.height*fitwidth)/image.width; }else{ imgd.width=image.width; imgd.height=image.height; } } else{ if(image.height>fitheight){ imgd.height=fitheight; imgd.width=(image.width*fitheight)/image.height; }else{ imgd.width=image.width; imgd.height=image.height; } } } } //预先载入图片 function preloadimages(arr){ var newimages=[] var arr=(typeof arr!="object")? [arr] : arr //确保参数总是数组 for (var i=0; i