Skip to content

Commit

Permalink
Merge pull request #73 from michaldudak/visibility-check
Browse files Browse the repository at this point in the history
Visibility check
  • Loading branch information
jonathan-fielding committed Mar 16, 2015
2 parents 1a22b5b + 71b7fe7 commit d5d320f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
11 changes: 10 additions & 1 deletion dist/echo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! echo.js v1.6.0 | (c) 2015 @toddmotto | https://github.com/toddmotto/echo */
/*! echo.js v1.7.0 | (c) 2015 @toddmotto | https://github.com/toddmotto/echo */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(function() {
Expand All @@ -19,7 +19,15 @@

var offset, poll, delay, useDebounce, unload;

var isHidden = function (element) {
return (element.offsetParent === null);
};

var inView = function (element, view) {
if (isHidden(element)) {
return false;
}

var box = element.getBoundingClientRect();
return (box.right >= view.l && box.bottom >= view.t && box.left <= view.r && box.top <= view.b);
};
Expand Down Expand Up @@ -90,6 +98,7 @@

if (!unload) {
elem.removeAttribute('data-echo');
elem.removeAttribute('data-echo-background');
}

callback(elem, 'load');
Expand Down
4 changes: 2 additions & 2 deletions dist/echo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@

var offset, poll, delay, useDebounce, unload;

var isHidden = function (element) {
return (element.offsetParent === null);
};

var inView = function (element, view) {
if (isHidden(element)) {
return false;
}

var box = element.getBoundingClientRect();
return (box.right >= view.l && box.bottom >= view.t && box.left <= view.r && box.top <= view.b);
};
Expand Down

0 comments on commit d5d320f

Please # to comment.