Skip to content

Instantly share code, notes, and snippets.

@solova
Forked from roman-manchenko/gist:7465866
Last active December 28, 2015 08:09
Show Gist options
  • Save solova/7469118 to your computer and use it in GitHub Desktop.
Save solova/7469118 to your computer and use it in GitHub Desktop.
(function() {
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
return define('jquery.in-viewport', ['jquery'], function($) {
return factory($, root);
});
} else {
return factory(root.jQuery, root);
}
})(this, function($, window) {
var $win = $(window);
$.extend($.expr[':'], {
"in-viewport": function(element) {
var viewport = {
top : $win.scrollTop(),
left : $win.scrollLeft()
};
viewport.right = viewport.left + $win.width();
viewport.bottom = viewport.top + $win.height();
var bounds = $(element).offset();
bounds.right = bounds.left + $(element).outerWidth();
bounds.bottom = bounds.top + $(element).outerHeight();
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
}
});
});
}).call(this);
Copy link

ghost commented Nov 14, 2013

gmail.com,,))))))))######,,,,.....+++++++///////>>>><<<<<

Copy link

ghost commented Nov 14, 2013

gmail.com,,))))))))######,,,,.....+++++++///////>>>><<<<<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment