Skip to content

Instantly share code, notes, and snippets.

@l3aconator
Created November 21, 2016 23:07
Show Gist options
  • Save l3aconator/59e4c8560809bfbf0ec28d7c6cd7417c to your computer and use it in GitHub Desktop.
Save l3aconator/59e4c8560809bfbf0ec28d7c6cd7417c to your computer and use it in GitHub Desktop.
setTimeout(function(){
// Scroll into to view for percentage graphs
function isElementInViewport( elem ) {
var $elem = $( elem );
// Get the scroll position of the page.
var scrollElem = ((navigator.userAgent.toLowerCase().indexOf( 'webkit' ) != -1) ? 'body' : 'html');
var viewportTop = $( scrollElem ).scrollTop();
var viewportBottom = viewportTop + $( window ).height();
// Get the position of the element on the page.
var elemTop = Math.round( $elem.offset().top );
var elemBottom = elemTop + $elem.height();
return ((elemTop < viewportBottom) && (elemBottom > viewportTop));
}
// Check if it's time to start the animation.
function checkAnimation() {
var $elem = $( '.graph-top' );
if ( isElementInViewport( $elem ) ) {
// Start the animation
$elem.addClass( 'start' );
} else {
$elem.removeClass( 'start' );
}
}
// Capture scroll events
$( window ).scroll( function () {checkAnimation();} );
},750);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment