JQuery picture delay loading and equal scaling plugin _jquery

Source: Internet
Author: User
Recently learning JS OOP, so I wrote this thing.
How to use:
$ (". Viewarea img"). Zoom ({height:74,width:103});
Effect Demo:
Http://demo.jb51.net/html/jquery_img/jquery_img.htm
Code:
Copy Code code as follows:

(function ($) {
$.fn.zoom = function (settings) {
Some default configurations;
Settings = $.extend ({
height:0,
width:0,
Loading: "Lightbox-ico-loading.gif"
},settings);
var images = this;
$ (images). Hide ();
var loadding = new Image ();
Loadding.classname= "Loadding"
LOADDING.SRC = settings.loading;
$ (images). After (loadding);
Pre-loading
var preload = function ($this) {
var img = new Image ();
IMG.SRC = $this. src;
if (img.complete) {
Processimg.call ($this);
Return
}
$this. src = loadding.src;//causes the wrong size to be obtained
Img.onload = function () {
$this. src = this.src; Will cause the error to get the size
Processimg.call ($this);
Img.onload=function () {};
}
}
Calculate picture size;
function processimg () {
if (settings.height===0| | Settings.width ===0) return;
var m = this.height-settings.height;
var n = this.width-settings.width;
if (m>n)
This.height = This.height>settings.height? Settings.height:
This.height;
Else
This.width = This.width >settings.width? Settings.width:
This.width;
$ (this). Next (". Loadding"). Remove ()
$ (this). Show ();
}
return $ (Images). each (function () {
Preload (this);
});
}
}) (JQuery);

The effect is this:

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.