Skip to content

Instantly share code, notes, and snippets.

@MikeMcChillin
Created April 13, 2013 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeMcChillin/5379164 to your computer and use it in GitHub Desktop.
Save MikeMcChillin/5379164 to your computer and use it in GitHub Desktop.
Animate any element when it enters the viewport. Currently set to lazy load images with fadeIn.
.already-visible
+opacity(1)
img
+opacity(0)
@include animated(1s, .3s)
/*! jQuery visible 1.0.0 teamdf.com/jquery-plugins | teamdf.com/jquery-plugins/license */
(function(c){c.fn.visible=function(e){var a=c(this),b=c(window),f=b.scrollTop();b=f+b.height();var d=a.offset().top;a=d+a.height();var g=e===true?a:d;return(e===true?d:a)<=b&&g>=f}})(jQuery);
#######################
# Lazy Load
#######################
# Makes use of the visible plugin
win = $(window)
allArticles = $("#article-slider article")
allArticles.each (i, el) ->
$(el).addClass "already-visible" if $(el).visible(true)
win.scroll (event) ->
allArticles.each (i, el) ->
el = $(el)
if el.visible(true)
el.addClass "fadeIn"
else
el.removeClass "fadeIn already-visible"
@xusai2014
Copy link

Sometimes throw the exceptions that property top is undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment