Created
July 19, 2013 01:25
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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