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