I have this jfiddle where:
- CSS animation starts when the
div
is on viewport. - I have an unknown number of
div
with an Icon, and 2 text lines.
What I need:
Each icon animated with a delay, with respect to the next one. In my jsfiddle all icons are animated simultaneously.
The actual program might have 1, 2, or 300
divs
with an icon, the solution must work for any number, not only with the 3 items of my jsfiddle example.I have bootstrap on
divs
, and with the scroll control, the animation only starts if thediv
appears on viewport, whilst on a notebook I get displayed 6 icons in a row, on a smartphone only 1.
var $animation_elements = $('.animation-element');
var $window = $(window);
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 + 15);
$.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');
}
});
$window.on('scroll resize', check_if_in_view);
$window.trigger('scroll');