Created
September 25, 2017 12:44
-
-
Save topleague/1ec3c5b94373a41e41aa45844b7c3488 to your computer and use it in GitHub Desktop.
JS Code for Fadeup Effect
This file contains hidden or 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
(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