javascript - 带航点的动画进度条

标签 javascript jquery html css jquery-waypoints

我试图在使用 waypont.js 滚动到进度条时触发进度条的动画

enter image description here


JS

function animateProgressBar(){
    $(".meter > span").each(function() {
        $(this)
            .data("origWidth", $(this).width())
            .width(0)
            .animate({
                width: $(this).data("origWidth")
            }, 1200);
    });
}

$(".meter > span").each(function() {
    var waypoint = new Waypoint({
      element: $(this),
      handler: function(direction) {
        animateProgressBar();
      }
    });
});

Fiddle

我得到了 Uncaught ReferenceError: Waypoint is not defined :(

任何提示/建议将不胜感激!

最佳答案

您需要在航路点的 handler 方法中调用您的 animateProgressBar 函数

function animateProgressBar(){
    $(".meter > span").each(function() {
        $(this)
            .data("origWidth", $(this).width())
            .width(0)
            .animate({
                width: $(this).data("origWidth")
            }, 1200);
    });
}


var waypoint = new Waypoint({
      element: document.getElementById('thing'),
      handler: function(direction) {
        animateProgressBar();
      }
});

关于javascript - 带航点的动画进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32527669/

相关文章:

jquery - 使用jquery同步调用

javascript - 输入警告 : Each child in a list should have a unique "key" prop. - react

html - 如何使用 axios 向 img html 标签发出视频流 http GET 请求?

javascript - 在嵌套组件中响应访问状态

javascript - 在 js window.open 之后打印 html/css 布局

jquery - 对于网站动画效果,执行性能更好 : CSS3 or jQuery?

html - 在 Div ID 中设置 Div 类的样式

javascript - 来自 api 的表数据

javascript - 文件夹中包含的页面上未调用 .js 文件

javascript - 将附加内容插入欧芹错误