var stats = [ {date: '31-12-2016', score: 12345, donations: 1234, trophylimit: 2400 } ]; var countdownStarted = false; var rollElements = [ 'score', 'donations', 'trophylimit' ]; var rollCounter = 0; var rollMax = 50; $(document).ready(function() { var countdownStarted = false; var inview = new Waypoint.Inview({ element: $('.js-datatable')[0], enter: function(direction) { if (!countdownStarted) { countdownStarted = true; rollNumbers(); } }, entered: function(direction) { console.log('Entered triggered with direction ' + direction) }, /* exit: function(direction) { notify('Exit triggered with direction ' + direction) }, exited: function(direction) { notify('Exited triggered with direction ' + direction) } */ }) }); function rollNumbers() { for (var i in rollElements) { $('.js-' + rollElements[i]).text(Math.round( (rollCounter / rollMax) * stats[0][rollElements[i]] )); } if (rollCounter < rollMax) { rollCounter++; setTimeout(function() { rollNumbers(); }, 10); } }