Play animation when content get into view

Viewed 5552

I've been searching on many posts but almost all of them are confusing.

I'm working with animate.css into a which is at the middle of my page. For default the animation is played when the page is loaded, but i want that it play when i reach the (when i'm scrolling).

Please, don't say about JS Reveal, i'd like to use the animation from animate.css

What i was trying: HTML

<!-- Others div above -->

<div class="row sf-medida" id="sf-medida" onscroll="Animar();">
<!-- Others div below -->

JS

  function Animar() {
setTimeout(function(){
   document.getElementById("sf-medida").style.visibility = "visible";
   $("#titulo-general").addClass("animated fadeInLeft");
   $(".sub-titulo").addClass("animated bounceInRight");

  $(".titulo-izquierda").addClass("animated swing");
  $(".texto-1").addClass("animated fadeIn");
  $(".texto-2").addClass("animated fadeIn");

},1000)

}

But it doesn't work, however, i've tried adding

window.addEventListener("scroll", Animar);

But what it does is that the animation is played whenever i scroll on the page,

3 Answers
Related