Created
April 9, 2017 05:28
-
-
Save Aleksandar-Mitic/14962cef617463377f3506eeb686f369 to your computer and use it in GitHub Desktop.
Scroll Position Detection
From https://www.sitepoint.com/scroll-based-animations-jquery-css3/
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
function check_if_in_view() { | |
var window_height = $window.height(); | |
var window_top_position = $window.scrollTop(); | |
var window_bottom_position = (window_top_position + window_height); | |
$.each($animation_elements, function() { | |
var $element = $(this); | |
var element_height = $element.outerHeight(); | |
var element_top_position = $element.offset().top; | |
var element_bottom_position = (element_top_position + element_height); | |
//check to see if this current container is within viewport | |
if ((element_bottom_position >= window_top_position) && | |
(element_top_position <= window_bottom_position)) { | |
$element.addClass('in-view'); | |
} else { | |
$element.removeClass('in-view'); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment