Skip to content

Instantly share code, notes, and snippets.

@robinbastien
Last active January 23, 2018 10:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinbastien/c69a3734ca68969084c8af6a49cb3cbc to your computer and use it in GitHub Desktop.
Save robinbastien/c69a3734ca68969084c8af6a49cb3cbc to your computer and use it in GitHub Desktop.
CSS Scroll Reveals (Simple WOW.js alternative)
// Get height of window and set an offset from bottom
var winHeight = $(window).height();
var offset = 50;
// Recalc height of window in case of resize
$(window).bind('resizeEnd', function() {
winHeight = $(window).height();
});
// When we scroll we do some checks...
$(window).on('scroll', function() {
// get current scrollPos
var trigger = $(window).scrollTop() + winHeight - offset;
// Rip through elements we're affecting
$('.has-scroll-reveal:not(.is-revealed)').each(function() {
var elementOffset = $(this).offset().top;
if( elementOffset < trigger ) {
$(this).addClass('is-revealed');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment