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/