ÔÚ´¦ÀíÍøҳͼƬʱ£¬ÌرðÊÇһЩͼƬÁбíµÄÓ¦ÓÃÀïÃ棬ºÜÄѱ£Ö¤Í¼Æ¬Í³Ò»´óС£¬Ö±½ÓÉèÖÃͼƬ´óСÓֻᵼÖÂͼƬÀÉ죬Ôì³ÉͼƬģºý£¬±¾ÎĽéÉܵĴúÂë¿ÉÒÔÔÚͼƬ¼ÓÔØÍê³Éºó×Ô¶¯°´±ÈÀýµ÷ÕûͼƬ´óС¡£
<script language="JavaScript" type="text/javascript"> // ˵Ã÷£ºÓà JavaScript ʵÏÖÍøҳͼƬµÈ±ÈÀýËõ·Å //µ÷Ó÷½Ê½£º // <img src="1148202890.jpg" alt="×Ô¶¯Ëõ·ÅºóµÄЧ¹û" onload="javascript:DrawImage(this,200,200);" /> //Èç¹ûͼƬ½Ï´ó£¬½¨ÒéÔÚͼƬ±êÇ©ÀïÃæͬʱÉèÖÃÆÚÍûµÄͼƬ´óС£¬ÕâÑù²»»áµ¼ÖÂÒ³ÃæÔÚ¼ÓÔØÖгſª£¬¸Ã´óС²»»áÓ°Ïì×îÖÕËõ·ÅЧ¹û¡£¿ÉÒÔÐÞ¸ÄÉÏÃæµÄ´úÂëΪ£º // <img src="1148202890.jpg" alt="×Ô¶¯Ëõ·ÅºóµÄЧ¹û" width="200" height="200" onload="javascript:DrawImage(this,200,200);" /> function DrawImage(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; } } } } </script>
(ÔðÈα༣ºadmin) |