Using jquery to achieve proportional scaling picture effect plug-in _jquery

Source: Internet
Author: User
Copy Code code as follows:

JQuery.fn.autoZoomLoadImage = function (scaling, width, height, loadpic) {
if (loadpic = = null) Loadpic = "Loading.gif";
Return This.each (function () {
var t = $ (this);
var src = $ (this). attr ("src");
var img = new Image ();
Alert ("Loading")
IMG.SRC = src;
Automatically scale pictures
var autoscaling = function () {
if (scaling) {
if (img.width > 0 && img.height > 0) {
if (img.width/img.height >= width/height) {
if (Img.width > width) {
T.width (width);
T.height ((img.height * width)/img.width);
}
else {
T.width (Img.width);
T.height (Img.height);
}
}
else {
if (Img.height > height) {
T.height (height);
T.width ((img.width * height)/img.height);
}
else {
T.width (Img.width);
T.height (Img.height);
}
}
}
}
}
Cached pictures are automatically read under processing FF
if (img.complete) {
Alert ("gettocache!");
AutoScaling ();
Return
}
$ (this). attr ("src", "");
var loading = $ ("T.hide ();
T.after (loading);
$ (IMG). Load (function () {
AutoScaling ();
Loading.remove ();
T.attr ("src", this.src);
T.show ();
Alert ("finally!")
});
});
}

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.