Statistics
| Branch: | Revision:

blinker / firefox.plugin / data / lib / jquery-onscreen.js @ 76dd22bd

History | View | Annotate | Download (722 Bytes)

1 a03cd52e Thies Pfeiffer
// onScreen jQuery plugin v0.2.1
2
// (c) 2011-2013 Ben Pickles
3
//
4
// http://benpickles.github.io/onScreen
5
//
6
// Released under MIT license.
7
;(function($) {
8
  $.expr[":"].onScreen = function(elem) {
9
    var $window = $(window)
10
    var viewport_top = $window.scrollTop()
11
    var viewport_height = $window.height()
12
    var viewport_bottom = viewport_top + viewport_height
13
    var $elem = $(elem)
14
    var top = $elem.offset().top
15
    var height = $elem.height()
16
    var bottom = top + height
17
18
    return (top >= viewport_top && top < viewport_bottom) ||
19
           (bottom > viewport_top && bottom <= viewport_bottom) ||
20
           (height > viewport_height && top <= viewport_top && bottom >= viewport_bottom)
21
  }
22
})(jQuery);