javascript - 拉斐尔圆圈内的文字

标签 javascript css raphael

我正在尝试用 Raphael 复制以下图像:

enter image description here

到目前为止,我只设法让圆圈工作。我如何获得模糊的灰色轮廓(显示剩余部分)和圆圈内的文本。

var score = 883
var amount = score/1000 * 100;

var archtype = Raphael("canvas", 200, 100);
archtype.customAttributes.arc = function (xloc, yloc, value, total, R) {
    var alpha = 360 / total * value,
        a = (90 - alpha) * Math.PI / 180,
        x = xloc + R * Math.cos(a),
        y = yloc - R * Math.sin(a),
        path;
    if (total == value) {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
        ];
    } else {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, +(alpha > 180), 1, x, y]
        ];
    }
    return {
        path: path
    };
};

var my_arc = archtype.path().attr({
    "stroke": "#00BB7B",
    "stroke-width": 7,
    arc: [50, 50, 0, 100, 30]
});

my_arc.animate({
    arc: [50, 50, amount, 100, 30]
}, 1500, "bounce");

Jsfiddle 在这里:http://jsfiddle.net/1eh7dmgu/

最佳答案

1) 平衡你可以显示只是把它放在绿色圆弧封闭的灰色圆弧下:

var remainder = archtype.path().attr({
    "stroke": "#eeeeee",
    "stroke-width": 7,
    arc: [50, 50, 100, 100, 30]
});

2)动画文本计数器也可以使用manual属性:

archtype.customAttributes.counter = function (counter) {
    return { text: counter, counter: counter }
}

[ http://jsfiddle.net/mwvLc0kb/ ]

关于javascript - 拉斐尔圆圈内的文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36446036/

相关文章:

javascript - jQuery UI 可对整个 div 进行排序

html - CSS 中的累积变换

javascript - 拆分 HTML 表格以适合视口(viewport)宽度

javascript - 我可以使用 Raphael.js 之类的东西在 HTML 窗口上方绘制矢量吗?

svg - raphael js 中的内联文本编辑

html - 如何为 svg 提供响应式设计?

javascript - Backbone.js - 更改事件未触发

javascript - 如何查找所有数字类 jQuery

javascript - http-proxy-middleware,如何复制所有/cookie header

html - 更改文本字段的宽度以显示所有字符