Skip to content

Instantly share code, notes, and snippets.

@topleague
Created September 25, 2017 12:44
Show Gist options
  • Save topleague/1ec3c5b94373a41e41aa45844b7c3488 to your computer and use it in GitHub Desktop.
Save topleague/1ec3c5b94373a41e41aa45844b7c3488 to your computer and use it in GitHub Desktop.
JS Code for Fadeup Effect
(function($) {
//* Make sure JS is enabled
document.documentElement.className = "js";
$(document).ready( function() {
//* Run 0.25 seconds after document ready for any instances viewable on load
setTimeout( function() {
animateObject();
}, 250);
});
$(window).scroll( function() {
//* Run on scroll
animateObject();
});
function animateObject() {
//* Define your object via class
var object = $( '.fadeup-effect' );
//* Loop through each object in the array
$.each( object, function() {
var windowHeight = $(window).height(),
offset = $(this).offset().top,
top = offset - $(document).scrollTop(),
percent = Math.floor( top / windowHeight * 100 );
if ( percent < 80 ) {
$(this).addClass( 'fadeInUp' );
}
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment