JQuery code for dynamically proportional adjustment of image size, image size jquery

Source: Internet
Author: User

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/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.