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

Easy pie chart does not: loading animation using Waypoint JS

本文关键字:Waypoint JS 加载 动画 使用 不能 简单      更新时间:2023-09-26

我正在设计一个单页滚动网页。在网页上,我使用简单的饼状图在我的技能页面。现在我想在到达技能页面时加载简单的饼状图动画。我使用了路径点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'
});

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

你可以试试这个代码:

    $(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));
          }
        });
        }
    }); 
});