easy-pie-chart icon indicating copy to clipboard operation
easy-pie-chart copied to clipboard

Start animation after scroll

Open thallysondias opened this issue 10 years ago • 3 comments

I want the graphic load after I make the scroll . I tried this code:

//scroll menu
            $(function(){

            $(window).scroll(function(){
                //create instance
                $('.chart').easyPieChart({
                    animate: 2000
                });
                //update instance after 5 sec
                if($(window).scrollTop() > $(window).height() + 600) { 
                    $('.chart').data('easyPieChart').update(100);
                } 
            });
        });

The problem is that when it comes to the point he does not make the loading smoothly. Only appears with the full graphic. 0 to 100...

thallysondias avatar Sep 09 '15 12:09 thallysondias

Hey @thallysondias I had the same issue and figured out that because you're firing the update function on every scroll event, the plugin can't animate it. I got around this by setting a boolean to check whether the chart had already been updated:


var isActive = false;

if($(window).scrollTop() > $(window).height() + 600) {
    if(isActive === false){ 
        $('.chart').data('easyPieChart').update(100);
        isActive = true;
    }
} 

Hope this helps :)

craig-mrare avatar Feb 27 '17 03:02 craig-mrare

on scroll events should be debounced in general

MarioPerini avatar Dec 05 '18 16:12 MarioPerini

The way to do this is to create an initial chart which is not animated without the barColor and then reset it + recreate again with the barColor and animation once scrolling.

Something like:

// prepare chart
$t.easyPieChart({
  animate    : { enabled : false },
  barColor   : false,
});
$(window).scroll(function(){
  // your logic
  $t.easyPieChart({
    animate    : { enabled : true },
    barColor   : '#fff',
  });
});

pfuhrmann avatar Feb 14 '19 01:02 pfuhrmann