I was wondering how to create a function that starts once a div gets a class.
I have a div which appears when scrolling (its an animation). Once it appears, it gets a class called "in-view"
.
The idea is to call a function everytime the div gets the class "in-view"
.
This is the div I'm talking about
When div .numbers
gets class "in-view"
, this function should be called...
Jquery
$(document).ready(function() {
$('.numbers.in-view .count-text').each(function () {
var $this = $(this);
$({ Counter: 0 }).animate({ Counter: $this.text() }, {
duration: 4000,
easing: 'swing',
step: function () {
$this.text(Math.ceil(this.Counter));
}
});
});
});
**html**
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-1 numbers animation-element slide-left testimonial">
<div class="fact-counter">
<div class="row clearfix">
<div class="counter-outer clearfix">
<article class="column col-sm-1">
<div class="count-icon"><i class="awesome fa-cogs"></i></div>
<div class="count-outer"><span class="count-text count-1">15</span></div>
<h4 class="counter-title">LOREM IPSUM DOLOR</h4>
</article>
<article class="column col-sm-1">
<div class="count-icon"><i class="awesome fa-heart-o"></i></div>
<div class="count-outer">+<span class="count-text count-2">5000</span></div>
<h4 class="counter-title">LOREM IPSUM DOLOR</h4>
</article>
<article class="column col-sm-1">
<div class="count-icon"><i class="awesome fa-globe-o"></i></div>
<div class="count-outer"><span class="count-text count-3">482</span></div>
<h4 class="counter-title">LOREM IPSUM DOLOR</h4>
</article>
<article class="column col-sm-1">
<div class="count-icon"><i class="awesome fa-globe-o"></i></div>
<div class="count-outer"><span class="count-text count-4">673</span></div>
<h4 class="counter-title">LOREM IPSUM DOLOR</h4>
</article>
</div>
</div>
</div>
</div>