javascript - Progressbar.js 结合两种效果

标签 javascript jquery html css progress-bar

我正在尝试结合来自 progressbar.js 的 2 个效果,但我无法让它工作。有人可以看一下并帮助我吗?

这是我的代码笔,包含我目前拥有的代码:

http://codepen.io/stephan-v/pen/MwQQzJ

var startColor = '#FC5B3F';
var endColor = '#9ec64d';

window.onload = function onLoad() {
    var circle = new ProgressBar.Circle('.progress', {
        color: startColor,
        duration: 3000,
        easing: 'bounce',
        strokeWidth: 8,

        // Set default step function for all animate calls
        step: function(state, circle, bar) {
            circle.path.setAttribute('stroke', state.color);
          bar.setText((bar.value() * 100).toFixed(0));
        }
    });

    // This will get the number from the page
    var value = ($('.progress').attr('value') / 100);

    // This will determine the circumference of the circle
    circle.animate(value, {
        from: {color: startColor},
        to: {color: endColor}
    });
};

我正在尝试将百分比文本与自定义动画相结合。可以在此页面上找到演示:

http://kimmobrunfeldt.github.io/progressbar.js/

我会毫不犹豫地奖励任何能帮助我解决这个问题的人。

最佳答案

需要在circle.animate方法中添加step函数

这就是您的 circle.animate 的外观

circle.animate(value, {
    from: {
        color: startColor
    },
    to: {
        color: endColor
    },
    step: function(state, circle, bar) {
        circle.path.setAttribute('stroke', state.color);
        console.log(circle);
        circle.setText((circle.value() * 100).toFixed(0));
    }
});

这是一个工作 JSFIDDLE 同样。

关于javascript - Progressbar.js 结合两种效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31192025/

相关文章:

javascript - 在静态 HTML 页面上设置 keith-wood CountDown

html - JSF2.2 标签使用 *.xhtml 但不使用 *.html

javascript - 在 php 中使用下拉菜单排序和检索数据

javascript - 仅将一个查询字符串参数解析为 Javascript 数组

jQuery 手机 : Override disabled ="disabled" style

javascript - 如何在country.js中设置默认国家并显示受尊重的国家?

javascript - 如何在 Firefox 中隐藏显示链接 URL 的状态栏

javascript - 与 shouldComponentUpdate 一起使用时,react-native-draggable-flatlist 拖放重置

javascript - 使用js添加按钮到灯箱

jquery - 输入字段 "onchange"事件jquery