Skip to content

Instantly share code, notes, and snippets.

@mattneary
Created June 23, 2012 20:26
Show Gist options
  • Save mattneary/2979829 to your computer and use it in GitHub Desktop.
Save mattneary/2979829 to your computer and use it in GitHub Desktop.
Visible in Parent
(function($, window) {
$.belowthefold = function(element, settings) {
var fold = $(window).height() + $(window).offset().top;
return fold <= $(element).offset().top - settings.threshold;
};
$.abovethetop = function(element, settings) {
var top = $(window).offset().top;
return top >= $(element).offset().top + $(element).height() - settings.threshold;
};
$.rightofscreen = function(element, settings) {
var fold = $(window).width() + $(window).offset().left;
return fold <= $(element).offset().left - settings.threshold;
};
$.leftofscreen = function(element, settings) {
var left = $(window).offset().left;
return left >= $(element).offset().left + $(element).width() - settings.threshold;
};
$.inviewport = function(element, settings) {
return !$.rightofscreen(element, settings) && !$.leftofscreen(element, settings) && !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
};
$.extend($.expr[':'], {
"below-the-fold": function(a, i, m) {
return $.belowthefold(a, {threshold : 0});
},
"above-the-top": function(a, i, m) {
return $.abovethetop(a, {threshold : 0});
},
"left-of-screen": function(a, i, m) {
return $.leftofscreen(a, {threshold : 0});
},
"right-of-screen": function(a, i, m) {
return $.rightofscreen(a, {threshold : 0});
},
"in-viewport": function(a, i, m) {
return $.inviewport(a, {threshold : 0});
}
});
})(jQuery, "#menuholder1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment