JQuery code for dynamically proportional adjustment of image size, image size jquery
JQuery code for dynamically proportional adjustment of image size:
Sometimes the size and size of an image are the locations. If the size and size of the uploaded image are stretched, the webpage may be deformed. Therefore, we must consider that controlling the image size cannot be too rough, directly determine the size of the image, which may cause deformation of the image. Therefore, you need to perform proportional scaling. The following is a piece of code that can implement this function.
The Code is as follows:
<script type="text/javascript">jQuery(window).load(function(){ jQuery("div.product_info img").each(function(){ DrawImage(this, 680, 1000); });}); 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>
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 11507.
For more information, see: http://www.softwhy.com/jquery/