jquery Achieve equal scale zoom image

Source: Internet
Author: User

In the layout of the page, sometimes you will encounter a large picture will make the page container large, beyond the specified area,

At this point we need to scale the picture proportionally so that the large picture adapts to the page layout.


View Demo http://itmyhome.com/jquery_image_scaling/


1, the page is like a piece


2. Use jquery to zoom the image

<script type= "text/javascript" >window.onload = function () {var w = 500;//Sets the maximum width or is dynamically obtained based on the external container of the IMG, for example: $ ("#demo") . width (); $ ("img"). each (function () {///If there are many pictures, use each () to traverse var img_w = $ (this). width ();//Picture width var img_h = $ (this). Height () ;//Picture height if (img_w > W) {//If the picture width exceeds the specified maximum width var height = (w * img_h)/img_w;//height is equal to the scale $ (this). css ({"width": w, "height" : height});//set width and height after scaling}}); $ (document). Ready (function () {///In this case, do not use the "Do You Know" in jquery ...}) </script>


jquery Achieve equal scale zoom image

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.