Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Created March 1, 2016 14:57
Show Gist options
  • Select an option

  • Save leepettijohn/df4aa73fd2db6a9e18b8 to your computer and use it in GitHub Desktop.

Select an option

Save leepettijohn/df4aa73fd2db6a9e18b8 to your computer and use it in GitHub Desktop.
Select items not on the screen or only partially visible
// onScreen jQuery plugin v0.2.1
// (c) 2011-2013 Ben Pickles
//
// http://benpickles.github.io/onScreen
//
// Released under MIT license.
;(function($) {
$.expr[":"].onScreen = function(elem) {
var $window = $(window)
var viewport_top = $window.scrollTop()
var viewport_height = $window.height()
var viewport_bottom = viewport_top + viewport_height
var $elem = $(elem)
var top = $elem.offset().top
var height = $elem.height()
var bottom = top + height
return (top >= viewport_top && bottom < viewport_bottom)
}
})(jQuery);
$('.twine-item:not(:onScreen)').css('display','none');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment