Created
November 21, 2016 23:07
-
-
Save l3aconator/59e4c8560809bfbf0ec28d7c6cd7417c to your computer and use it in GitHub Desktop.
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
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