JQuery achieves proportional scaling for images.

Source: Internet
Author: User

JQuery achieves proportional scaling for images.

Proportional scaling of images implemented by jQuery:
If a container contains a larger image than the container, the layout may be faulty. Even if the container is not large, it may not look beautiful enough. At this time, the image size must be limited, of course, it cannot be deformed. Otherwise, it will be difficult to understand. The following describes how to use jQuery to implement proportional scaling.
The Code is as follows:

 

<Div id = "demo">  </div>

 

The following is the scaling Code implemented by jQuery:

$ (Function () {var w = $ ("# demo "). width (); // container width $ ("# demo img "). each (function () {// if there are many images, we can use each () to traverse var img_w = $ (this ). width (); // Image width var img_h = $ (this ). height (); // Image height if (img_w> w) // if the image width exceeds the container width, the {var height = (w * img_h)/img_w must be broken; $(this).css ({"width": w, "height": height}); // set the width and height after scaling }})})

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9602.

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.