I have a jQuery number counter that works great but it runs as soon as the page loads. What I am trying to do is work out how to get it to run when the element come into view? This is my current markup
EDIT
Got the desired effect using waypoints. Updated jQuery below
$('#counter').waypoint(function (direction) {
$('.count').each(function () {
var $this = $(this);
jQuery({
Counter: 0
}).animate({
Counter: $this.text()
}, {
duration: 2000,
easing: 'swing',
step: function () {
$this.text(Math.ceil(this.Counter));
}
});
});
}, {
offset: '80%'
});
#counter {
position: relative;
color: #fff;
margin-top: 600px;
}
.counters {
padding: 100px 0;
width: 33.333%;
float: left;
}
#counter-1 {
background: #393939;
}
#counter-2 {
background: #494949;
}
#counter-3 {
background: #595959;
}
.line-numbers {
text-align: center;
display: block;
font-size: 55px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id="counter">
<div id="counter-1" class="counters">
<span class="line-numbers count">2000</span>
</div>
<div id="counter-2" class="counters">
<span class="line-numbers count">2500</span>
</div>
<div id="counter-3" class="counters">
<span class="line-numbers count">150</span>
</div>
</section>