<script>
jQuery(document).ready(function($) {
    var counted = false;

    $(window).on("scroll", function() {
        var section = $("#achievements");
        if (!counted && section.length) {
            var sectionTop = section.offset().top;
            var scrollTop = $(window).scrollTop();
            var windowHeight = $(window).height();

            if (scrollTop + windowHeight > sectionTop) {
                $(".text-to-be-counted").each(function() {
                    var $this = $(this);
                    var countTo = parseInt($this.text());
                    $this.text(0).animate(
                        { num: countTo },
                        {
                            duration: 1500,
                            step: function(now) {
                                $this.text(Math.floor(now));
                            },
                            complete: function() {
                                $this.text(countTo);
                            }
                        }
                    );
                });
                counted = true;
            }
        }
    });
});
</script>
