【问题标题】:Raphael.js: Drawing a circle with an edge border and a fill colourRaphael.js:绘制一个带有边缘边框和填充颜色的圆
【发布时间】:2013-06-18 09:23:15
【问题描述】:

用数字绘制 SVG 令人困惑,但非常非常有用。通过修改其他人的示例,我有一个 Raphael.js 函数,该函数需要 60 秒才能在圆形周围绘制一条粗绿线,其中心有文本。这里是JSFiddle形式,容器Div上有黑色背景,表示圆圈上目前没有背景色:

http://jsfiddle.net/8NZfU/1/

这是 JS:

//60s circular timer
function timer60s() {

var archtype = Raphael("canvas60s", 200, 200);
var set = archtype.set();

function drawCircle() {
  var archtype = Raphael("canvas60s", 200, 200);
  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": "#339933",
      "stroke-width": 10,
      arc: [100, 100, 0, 100, 50]
  });



  my_arc.animate({
     arc: [100, 100, 100, 100, 50]
  }, 60000);


} //end drawCircle





    drawCircle();

  } // end timer60s

  timer60s();

我想要的是在绘制圆弧的整个圆圈内创建白色背景的效果。我还想在弧线的任一侧添加静态的细绿色边框,以便看起来弧线在线条之间缓慢填充。

我在 CSS 或 Raphael 中都没有成功绘制此背景 + 边框 - 任何人都可以根据我的 JSFiddle 提出一种可行的方法吗?

【问题讨论】:

  • 这是一个很好的解释和很好的问题。解决方案看起来也很整洁。 :)

标签: javascript svg raphael


【解决方案1】:

我不确定,但你能画第二个圆圈吗?

像这样:http://jsfiddle.net/5knjn/

archtype.circle(100, 100, 50).attr({
    "fill": "#fff",
    "stroke": "#fff",
    "stroke-width": "10"
});

部分没看懂:

I also want to add static thin green borders to either side of the arc, so that it appears that the arc is slowly filling in between the lines.

所以我想出了:) http://jsfiddle.net/5knjn/1/

我也不喜欢你在画布中输入文本的方式。

你可以使用Raphael.text()

包含文字:http://jsfiddle.net/5knjn/2/

【讨论】:

  • 感谢所有示例,这非常有用!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-16
  • 1970-01-01
  • 2013-08-27
  • 2015-08-03
  • 2015-10-23
  • 2012-10-26
  • 2021-08-24
相关资源
最近更新 更多