Last active
June 22, 2016 03:31
-
-
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
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
.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; | |
} |
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
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