Skip to content

Commit 4f16e34

Browse files
author
capynet
committed
Compile dist.
1 parent 0a00788 commit 4f16e34

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

dist/isInViewport.jquery.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,65 @@
77
!function ($) {
88
'use strict'
99

10-
var plugin
11-
1210
var Class = function (el, cb) {
13-
plugin = this
14-
this.$el = $(el)
15-
this.cb = cb
16-
watch()
17-
return this
18-
}
11+
this.$el = $(el);
12+
this.cb = cb;
13+
this.watch();
14+
return this;
15+
};
1916

20-
/**
21-
* Checks if the element is in.
22-
*
23-
* @returns {boolean}
24-
*/
25-
function isIn () {
26-
var $win = $(window)
27-
var elementTop = plugin.$el.offset().top
28-
var elementBottom = elementTop + plugin.$el.outerHeight()
29-
var viewportTop = $win.scrollTop()
30-
var viewportBottom = viewportTop + $win.height()
31-
return elementBottom > viewportTop && elementTop < viewportBottom
32-
}
17+
Class.prototype = {
3318

34-
/**
35-
* Launch a callback indicating when the element is in and when is out.
36-
*/
37-
function watch () {
38-
var _isIn = false
19+
/**
20+
* Checks if the element is in.
21+
*
22+
* @returns {boolean}
23+
*/
24+
isIn: function isIn() {
25+
var _self = this;
26+
var $win = $(window);
27+
var elementTop = _self.$el.offset().top;
28+
var elementBottom = elementTop + _self.$el.outerHeight();
29+
var viewportTop = $win.scrollTop();
30+
var viewportBottom = viewportTop + $win.height();
31+
return elementBottom > viewportTop && elementTop < viewportBottom;
32+
},
3933

40-
$(window).on('resize scroll', function () {
34+
/**
35+
* Launch a callback indicating when the element is in and when is out.
36+
*/
37+
watch: function () {
38+
var _self = this;
39+
var _isIn = false;
4140

42-
if (isIn() && _isIn === false) {
43-
plugin.cb.call(plugin.$el, 'entered')
44-
_isIn = true
45-
}
41+
$(window).on('resize scroll', function () {
4642

47-
if (_isIn === true && !isIn()) {
48-
plugin.cb.call(plugin.$el, 'leaved')
49-
_isIn = false
50-
}
43+
if (_self.isIn() && _isIn === false) {
44+
_self.cb.call(_self.$el, 'entered');
45+
_isIn = true;
46+
}
5147

52-
})
53-
}
48+
if (_isIn === true && !_self.isIn()) {
49+
_self.cb.call(_self.$el, 'leaved');
50+
_isIn = false;
51+
}
52+
53+
})
54+
}
55+
56+
57+
};
5458

5559
// jQuery plugin.
5660
//-----------------------------------------------------------
5761
$.fn.isInViewport = function (cb) {
5862
return this.each(function () {
59-
var $element = $(this)
60-
var data = $element.data('isInViewport')
63+
var $element = $(this);
64+
var data = $element.data('isInViewport');
6165
if (!data) {
62-
$element.data('isInViewport', (new Class(this, cb)))
66+
$element.data('isInViewport', (new Class(this, cb)));
6367
}
6468
})
6569
}
6670

67-
}(window.jQuery)
71+
}(window.jQuery);

dist/isInViewport.jquery.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)