Last active
January 23, 2018 10:13
-
-
Save robinbastien/c69a3734ca68969084c8af6a49cb3cbc to your computer and use it in GitHub Desktop.
CSS Scroll Reveals (Simple WOW.js alternative)
This file contains 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
// 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