This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
forked from furf/ReVIEW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.review.js
51 lines (47 loc) · 1.61 KB
/
jquery.review.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* jQuery ReVIEW
* An ultra lightweight jQuery / Zepto plugin for lazy loading elements
* https://github.com/resrcit/ReVIEW
*
* Licensed under the MIT license.
* Copyright 2013 Dominic Fee
* http://www.resrc.it
*/
(function ($) {
$.fn.review = function () {
var options = $.extend({threshold: 0, callback: function () {
}}, arguments[0] || {}),
$w = $(window),
th = options.threshold,
element = this,
inView,
isElementInView;
this.one("reviewElement", function () {
options.callback.call(this);
});
function reviewElement() {
isElementInView = element.filter(function () {
/**
* Hat tip to https://github.com/luis-almeida/unveil
* for adapting his inview window calculations
*/
var $e = $(this),
wt = $w.scrollTop(),
wlt = $w.scrollLeft(),
wb = wt + $w.height(),
wlb = wlt + $w.width(),
et = $e.offset().top,
el = $e.offset().left,
eb = et + $e.height(),
elb = el + $e.width();
return eb >= wt - th && et <= wb + th && elb >= wlt - th && el <= wlb + th;
});
inView = isElementInView.trigger("reviewElement");
element = element.not(inView);
}
$w.scroll(reviewElement);
$w.resize(reviewElement);
reviewElement();
return this;
};
})(window.jQuery || window.Zepto);