jQuery :above-the-fold Selector

Language: JavaScript

// This is currently not playing nice in IE7 -- working on a fix


// $('div:above-the-fold') checks to see if the div is above the fold (of the window)
// $('li:last:above-the-fold(div)') checks to see if the last li is above the fold of the div

$.extend($.expr[':'], {
  "above-the-fold": function(a, i, m) {
    var container = m[3];
    var fold;
    if (typeof container === "undefined") {
      fold = $(window).height() + $(window).scrollTop();
    } else {
      if ($(container).length == 0 || $(container).offset().top == null) return false;
      fold = $(container).offset().top + $(container).height();
    }
    return fold >= $(a).offset().top;
  } 
});
Reveal More
Added 6 months ago by Posterized_grey_80_normal scottymac