javascript - Multiple js progressbars on the same page? - Stack Overflow

I'm working on a project with progressbar.js and I want to have multiple progress bars on my page.

I'm working on a project with progressbar.js and I want to have multiple progress bars on my page. There is a dynamic amount so I'm not sure ahead of time how much progressbars I will have on the page.

I my JSFiddle I have simply duplicated the code and gave the second progressbar a .progress2 class. Ideally I would want to have the progressbar working for each element by simply giving it a .progress class

/

var circle = new ProgressBar.Circle('.progress', {
    color: startColor,
    easing: 'linear',
    strokeWidth: 8,
    duration: 1500,
    text: {
        value: '0'
    }
});

Obviously I guess I would start by gathering the values and putting those into an array but I can't even get that working. Could somebody give me a push in the right direction since I'm not that good with javascript.

I would be really grateful if somebody would take a look and tell me if this can even be done the way I would want it.

I'm working on a project with progressbar.js and I want to have multiple progress bars on my page. There is a dynamic amount so I'm not sure ahead of time how much progressbars I will have on the page.

I my JSFiddle I have simply duplicated the code and gave the second progressbar a .progress2 class. Ideally I would want to have the progressbar working for each element by simply giving it a .progress class

http://jsfiddle/8xa87k31/497/

var circle = new ProgressBar.Circle('.progress', {
    color: startColor,
    easing: 'linear',
    strokeWidth: 8,
    duration: 1500,
    text: {
        value: '0'
    }
});

Obviously I guess I would start by gathering the values and putting those into an array but I can't even get that working. Could somebody give me a push in the right direction since I'm not that good with javascript.

I would be really grateful if somebody would take a look and tell me if this can even be done the way I would want it.

Share Improve this question asked Jul 13, 2015 at 22:23 Stephan-vStephan-v 20.4k32 gold badges124 silver badges211 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Evening Stephan,

I think this is what you're looking for: http://jsfiddle/8xa87k31/499/

$('.progress').each(function() {
    var circle = new ProgressBar.Circle(this, {
        color: startColor,
        easing: 'linear',
        strokeWidth: 8,
        duration: 1500,
        text: {
            value: '0'
        }
    });

    var value = ($(this).attr('value') / 100);

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

See? No big deal! :-)

NB: I'm convinced, this could be improved.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745134203a4613122.html

相关推荐

  • javascript - Multiple js progressbars on the same page? - Stack Overflow

    I'm working on a project with progressbar.js and I want to have multiple progress bars on my page.

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信