forked from krio/jquery-image-loader-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.krioImageLoader.js
36 lines (33 loc) · 1.26 KB
/
jquery.krioImageLoader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Krio Image Loader Jquery Plugin v1
* http://krio.me/jquery-image-loader-plugin
* http://github.com/jquery-image-loader-plugin
*/
(function ($) {
$.fn.krioImageLoader = function (options) {
var imagesToLoad = $(this).find("img").css({opacity: 0, visibility: "hidden"}).addClass("krioImageLoader"),
imagesToLoadCount = imagesToLoad.size(),
opts = $.extend({}, $.fn.krioImageLoader.defaults, options);
var checkIfLoadedTimer = setInterval(function () {
if (!imagesToLoadCount) {
clearInterval(checkIfLoadedTimer);
} else {
imagesToLoad.filter(".krioImageLoader").each(function () {
if (this.complete) {
fadeImageIn(this);
imagesToLoadCount--;
}
});
}
}, opts.loadedCheckEvery);
var fadeImageIn = function (imageToLoad) {
$(imageToLoad).css({visibility: "visible"}).animate({opacity: 1}, opts.imageEnterDelay, function () {
$(imageToLoad).removeClass("krioImageLoader");
});
};
};
$.fn.krioImageLoader.defaults = {
loadedCheckEvery: 350,
imageEnterDelay: 300
};
})(jQuery);