Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wow.js repeat animation every time you scroll up or down

I'm pretty new with Jquery. I would like that my animations with Wow.js could run more than once time. For instance: i scroll to the bottom of my page and see all the animations, and if i scroll back to the top i see again the animations like when you scroll down. I hope that I explained myself. I have already seen many websites that repeats the animations on theirs pages but unfortunately I don't remember them and I can't provide a link.

I have already tried this:

$(window).scroll(function(){
    new WOW().init();
}

But it repeat the animations also if you scroll a little and it's pretty ugly to see. I try to explain me better: I have a with my animation and if it is focused the animation is triggered, then i scroll down to another div and the previous div is no more visible(not in the window viewport), then again i scroll back to my div with animation and the animation is triggered again.

I'm sorry for this messy question but I really don't know how to explain it.

Thanks in advance!

like image 860
Automatik Avatar asked Oct 17 '15 13:10

Automatik


People also ask

What is Wowjs?

Wow. js is a JavaScript library that generates CSS animations as you scroll along any webpage. It integrates CSS3 based animations in the websites. In the default case, you can use these animations by triggering animate.

What is scroll triggered animation?

Scroll Triggered Animations is a highly customisable, yet user-friendly interface for implementing CSS animations correctly and efficiently throughout your WordPress website. Whether you're a highly-skilled web guru, a content editor or you've got minimal knowledge of web coding, STA makes the animation procedure easy.

What is scroll animation?

A scrolling animation is an animation where one or multiple elements get animated while the visitor scrolls up or down the page. The animations can be of any kind: moving elements, fading effects, change in color, shape or size, or anything else that comes to your mind.


1 Answers

This example by Benoît Boucart shows how the animation can be "reset" when the user scrolls out of view and back in. The key here is the second function that removes the animation css class when the element scrolls out of view. I wish WOW.js would implement this, but they've indicated that they don't plan to.

http://codepen.io/benske/pen/yJoqz

Snippet:

// Showed...
$(".revealOnScroll:not(.animated)").each(function () {
  var $this     = $(this),
      offsetTop = $this.offset().top;

  if (scrolled + win_height_padded > offsetTop) {
    if ($this.data('timeout')) {
      window.setTimeout(function(){
        $this.addClass('animated ' + $this.data('animation'));
      }, parseInt($this.data('timeout'),10));
    } else {
      $this.addClass('animated ' + $this.data('animation'));
    }
  }
});
// Hidden...
$(".revealOnScroll.animated").each(function (index) {
   var $this     = $(this),
       offsetTop = $this.offset().top;
   if (scrolled + win_height_padded < offsetTop) {
     $(this).removeClass('animated fadeInUp flipInX lightSpeedIn')
   }
});
like image 142
Tony He Avatar answered Oct 12 '22 23:10

Tony He