Jquery and Other proportional scaling image extensions

Source: Internet
Author: User

Recently, I made a small image management system for a customer. The image directly uses the address without going through the server. However, he asked the image not to be distorted or distorted. In this way, we need to use JS on the client. Fortunately, with jQuery, it is more convenient to do this. I wrote a small plug-in www.2cto.com autosize.

Suppose there is such an image

The image size is forcibly set to 200*300. If the image size of the address is not, the image will be deformed. So I want to find a way to maximize the image proportion by 200*300. So we have the following plug-ins.

It is easy to use. Before use, you must introduce the jquery library and my image. js in the header.

<Script type = "text/javascript" src = "static/js/jquery-1.6.1.min.js"> </script>

<Script type = "text/javascript" src = "static/js/image. js"> </script>

Then we add some materials to the image.

Here, autosize = 'yes' is the default selector. image. js has been bound to process images with this tag when the document is loaded.

Pos = '0' indicates that the long image is displayed in the center. There are three options for this value. If this value is not specified, it is displayed in the center, or 0.

-1: on top

0: in the middle

1: Bottom

The horizontal direction is always centered.

In fact, we can do this by adding no other code. The above picture is centered.

You can also manually specify the image to be processed.

$ ("Img"). autosize ('#999 ');

In this way, you can select all images and process them. An optional parameter is provided to indicate the filled background color. If you do not enter this parameter, the default fill is a white http://www.bkjia.com/uploadfile/2011/0908/20110908053237294.rar
 

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.