michalsnik / aos

Animate on scroll library
MIT License
26.84k stars 2.6k forks source link

All animations firing at once unless browser window is resized #82

Closed Krucial92 closed 7 years ago

Krucial92 commented 7 years ago

Hello,

Thanks for the awesome plugin.

On page I am fading in 6 different images which are all using the same animation and settings. The problem is that all these animations are firing as soon as I have scrolled onto the first image. Only once the browser window is resized, the animations appear in order when they are coming onto the screen.

Any idea what the problem is?

<div data-aos="fade-in" id="<?php echo $id ?>" data-aos-delay="500">
    <?php echo do_shortcode( $content ); ?>
</div>

And initalizing in my JS file:

jQuery(document).ready(function ($) {
    "use strict";

    /**
     * Initialize AOS Animations
     */

    AOS.init({
        duration: 1200,
        easing: 'ease-in-out-sine'
    });

});

So just to confirm, that once the browser window is resized, all animations appear at the right times. But unless it is resized (on page load), they are all firing in one go once I scroll to the first image.

Any idea what the issue is? Thanks

ranjithrathnaker commented 7 years ago

Have the same problem.Any idea what the issue is?

michalsnik commented 7 years ago

Hey, if you're using jQuery you can refresh position of corresponding trigger points using:

$(window).on('load', function() {
  AOS.refresh();
});

It looks like your elements on document.ready have not set height yet - it might happen when you load images without setting height. In this case all elements start at the same point - and if the script sees them like this while performing calculations, they will eventually all animate after you reach their initial position. Refreshing their position on window.load should help you.

Hope this helps!

Krucial92 commented 7 years ago

Cool, thanks Michael, will give this a shot.

ranjithrathnaker commented 7 years ago

Thanks Michael.Thanks for the solution it's perfect now.

michalsnik commented 7 years ago

Cool, I'm closing this issue for now. Provided solution should also work for you @Krucial92 :)