V
V
Vasily Petrov2016-11-12 20:43:13
JavaScript
Vasily Petrov, 2016-11-12 20:43:13

Animated number change in real time?

The page has a div that contains a number. This number is added from the php file (using include), and the number gets into the php file from the database. DB>>>php-file>>>page. The div that contains the number is updated every 3000ms.
With this code, the number on the page is animated: (the number is counted from 1, for example, 1,2,3,4 and until the number itself is displayed)

$(window).scroll(startCounter);
function startCounter() {
    if ($(window).scrollTop() > 3000) {
        $(window).off("scroll", startCounter);
        $('.Count').each(function () {
            var $this = $(this);
            jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
                duration: 4000,
                easing: 'swing',
                step: function (now) {
                    $this.text(now.toFixed(2)); 
                }
            });
        });
    }
}

When a number changes in the database, accordingly, it changes in the php file, and therefore on the page, but it changes without animation.
How to make it change with animation, at least in a big way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question