On a Wordpress page, I have this code to start a count-up, but I only want it to start counting when the user has scrolled far enough down the page so that it appears onscreen (it's in a containing DIV called "three-counter-section").
How do you retrofit this code to enable that?
$('.counter').each(function() {
var $this = $(this),
countTo = $this.attr('data-count');
$({ countNum: $this.text()}).animate({
countNum: countTo
},
{ duration: 11000,
easing:'easeInOutCubic',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);
}
});
});