F
F
fl4sh12016-10-21 14:11:17
css
fl4sh1, 2016-10-21 14:11:17

How to make it so that when you scroll and reach the bottom of the site, statistics numbers quickly begin to be calculated?

Good afternoon, I want to make an unobtrusive effect. A person enters the landing page, scrolls, and when it comes to the moment with statistics, the numbers start from zero to quickly count up to a certain amount

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sklyarov, 2016-10-21
@fl4sh1

$(window).scroll(function() {
        $('#site-promo').each(function(){
        var imagePos = $(this).offset().top;

        var topOfWindow = $(window).scrollTop();
            if (imagePos < topOfWindow+300) {
                $('.way-img').addClass("stretchRight vv");
            }
        });
    });

What does the code do?
Takes an id (for example, your block with numbers that need to be animated), when the user scrolls to this block, 300 pixels before this block, the animation is assigned to the .way-img block.
Similarly with your task: insert the ID of the container with numbers into the id, after which you assign an animation to each number, this line is responsible for this (correct for yourself):
$('.way-img').addClass("stretchRight vv");

A
Anton Sukhinin, 2016-10-21
@AntonSu

Alternatively use jquery.animateNumber.
aishek.github.io/jquery-animateNumber
And use a condition to trigger it something like this:
if (($(document).scrollTop() + $(window).height()) > ($('.animate- number-block').offset().top + 100)) {
animate_number();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question