Skip to content

Instantly share code, notes, and snippets.

@sivagao
Created July 19, 2013 01:25
Show Gist options
  • Save sivagao/6034399 to your computer and use it in GitHub Desktop.
Save sivagao/6034399 to your computer and use it in GitHub Desktop.
Slide In (as you scroll down) Boxes @ nexus 7 Google+ app http://css-tricks.com/slide-in-as-you-scroll-down-boxes/
(function($) {
/**
* @author Sam Sehnert
* @desc A small plugin that checks whether elements are within
* the user visible viewport of a web browser.
* only accounts for vertical position, not horizontal.
*/
$.fn.visible = function(partial) {
var $t = $(this),
$w = $(window),
viewTop = $w.scrollTop(),
viewBottom = viewTop + $w.height(),
_top = $t.offset().top,
_bottom = _top + $t.height(),
compareTop = partial === true ? _bottom : _top,
compareBottom = partial === true ? _top : _bottom;
return ((compareBottom <= viewBottom) && (compareTop >= viewTop));
};
})(jQuery);
var win = $(window);
var allMods = $(".module");
// Already visible modules
allMods.each(function(i, el) {
var el = $(el);
if (el.visible(true)) {
el.addClass("already-visible");
}
});
win.scroll(function(event) {
allMods.each(function(i, el) {
var el = $(el);
if (el.visible(true)) {
el.addClass("come-in");
}
});
});
.come-in {
transform: translateY(150px);
animation: come-in 0.8s ease forwards;
}
.come-in:nth-child(odd) {
animation-duration: 0.6s; /* So they look staggered */
}
@keyframes come-in {
to { transform: translateY(0); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment