progressbar.js icon indicating copy to clipboard operation
progressbar.js copied to clipboard

How to start the animation only when the circle appears in browser's view (on scrolling)?

Open asif-jalil opened this issue 4 years ago • 8 comments

How can i animate circle while scrolling down to page ? My page is quite long and this plugin come just above the footer, but it animate, when page loads and when scroll down, can not see the circle progress effect ?

asif-jalil avatar May 22 '20 22:05 asif-jalil

I have the same doubt! Want the progressBar start the animation when it appears on the screen.

christopher-alves-dev avatar May 23 '20 12:05 christopher-alves-dev

You would need to use an Intersectional Observer

roryaherne avatar May 25 '20 09:05 roryaherne

If you're using jQuery, have a look at the jquery-appear plug-in. It will achieve what you're looking for.

dearsina avatar May 26 '20 09:05 dearsina

@dearsina

If you're using jQuery, have a look at the jquery-appear plug-in. It will achieve what you're looking for.

I saw the plugin. But i don't understand how to integrate with it. Can you write me the code i need?

asif-jalil avatar May 26 '20 13:05 asif-jalil

Try something like this:

    // Enable element's appearance to be a triggering event
    $.appear('.progress-bar-class-name');

    // Set up a listener to the load-more-button appearing
    $('.progress-bar-class-name').on('appear', function(event, all_appeared_elements) {
        //Put your progressbar initiate code here. Will only trigger once the bar is visible.
    });

dearsina avatar May 26 '20 17:05 dearsina

Try something like this:

    // Enable element's appearance to be a triggering event
    $.appear('.progress-bar-class-name');

    // Set up a listener to the load-more-button appearing
    $('.progress-bar-class-name').on('appear', function(event, all_appeared_elements) {
        //Put your progressbar initiate code here. Will only trigger once the bar is visible.
    });

I am failed to work with it.

asif-jalil avatar Jun 07 '20 16:06 asif-jalil

This may not be the right forum for it, perhaps ask a question on StackOverflow and list what you tried and what errors you're getting. Feel free to tag me and I will try to help.

dearsina avatar Jun 07 '20 16:06 dearsina

Like this using sal:

import sal from 'sal.js'
    if (document.querySelector('.progress-circle') != null) {

        sal({
            selector: '.progress-circle'
        });

        document.addEventListener('sal:in', ({ detail }) => {
            let circle = new ProgressBar.Circle(detail.target, {
                // options...
                }
            });

            circle.animate();
        });
    }

nicolaskopp avatar Nov 26 '21 15:11 nicolaskopp