Skip to content

Instantly share code, notes, and snippets.

@sukhikh18
Last active April 29, 2020 08:37
Show Gist options
  • Save sukhikh18/339193ece679348d9fd5dfb4cf761d43 to your computer and use it in GitHub Desktop.
Save sukhikh18/339193ece679348d9fd5dfb4cf761d43 to your computer and use it in GitHub Desktop.
On scroll element appear. Use: $(this).scrollIn()
$.fn.scrollIn = function() {
var $window = $(window),
scrollTop = $window.scrollTop(),
viewport = {
top: scrollTop,
bottom: scrollTop + $window.height()
},
bounds = this.offset();
bounds.bottom = bounds.top + this.outerHeight();
return (!(viewport.bottom < bounds.top || viewport.top > bounds.bottom));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment