Skip to content

Instantly share code, notes, and snippets.

@GavinJaynes
Last active June 22, 2016 03:31
Show Gist options
  • Save GavinJaynes/29bd9e48335720ee4db9 to your computer and use it in GitHub Desktop.
Save GavinJaynes/29bd9e48335720ee4db9 to your computer and use it in GitHub Desktop.
Simple animation for elements as they enter the view port. Update: Just use WOW.js
.selector {
width: 100%;
height: 300px;
margin: 40px;
background: black;
/* The defaults */
opacity: 0;
margin-top: 90px;
transition: all 500ms ease;
-moz-transition: all 500ms ease;
-webkit-transition: all 500ms ease;
}
.selector.on {
/* The in view styles */
opacity: 1;
margin-top: 20px;
transition: all 500ms ease;
-moz-transition: all 500ms ease;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
}
var tiles = $('.selector');
$(window).scroll(function() {
tiles.each(function(i) {
var a = $(this).offset().top + $(this).height();
var b = $(window).scrollTop() + $(window).height();
if (a < b) $(this).addClass('on');
if (a > b) $(this).removeClass('on');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment