简单的饼图不会:使用Waypoint JS加载动画

时间:2014-06-26 10:41:08

标签: javascript jquery html jquery-waypoints easypie

我正在设计单页滚动网页。在网页中,我在技能页面中使用简单的饼图。现在我想在到达技能页面时加载简单的饼图动画。 我使用了航点js,但它不起作用。当我在技能页面时加载动画但是当我在顶部并刷新页面&而不是去技能页面,它不起作用。

我的代码如下所示

custom.js:

jQuery('.skill').waypoint(function() {
$('.chart1').easyPieChart({
animate: 4000,
barColor: '#000',
trackColor: '#ddd',
scaleColor: '#e1e1e3',
lineWidth: 15,
size: 152,
});
}, {
triggerOnce: true,
offset: 'bottom-in-view'
});

现在我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

    $(window).scroll( function(){

    /* Check the location of each desired element */
    $('.skill').each( function(i){

        var bottom_of_object = $(this).offset().top + $(this).outerHeight();
        var bottom_of_window = $(window).scrollTop() + $(window).height();

        /* If the object is completely visible in the window, fade it in */
        if( bottom_of_window > bottom_of_object ){

        $('.skill').easyPieChart({
          size: 140,
          lineWidth: 6,
          lineCap: "square",
          barColor: "#22a7f0",
          trackColor: "#ffffff",
          scaleColor: !1,
          easing: 'easeOutBounce',
          animate: 5000,
          onStep: function(from, to, percent) {
          $(this.el).find('.percent').text(Math.round(percent));
          }
        });

        }

    }); 

});