Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拉斐尔:如何在div中居中旋转_Javascript_Raphael - Fatal编程技术网

Javascript 拉斐尔:如何在div中居中旋转

Javascript 拉斐尔:如何在div中居中旋转,javascript,raphael,Javascript,Raphael,我想在div的中心创建cricle。这是我的 如果我将amount设置为75,它将显示圆的正确位置,但如果我将变量amount更改为小于75,则圆的位置将从奇怪的地方开始。 这是我的密码 var amount = 75; var archtype = Raphael("canvas", 500, 500); archtype.customAttributes.arc = function (xloc, yloc, value, total, R) { var alpha = 360 /

我想在div的中心创建cricle。这是我的 如果我将amount设置为75,它将显示圆的正确位置,但如果我将变量amount更改为小于75,则圆的位置将从奇怪的地方开始。
这是我的密码

var amount = 75;
var archtype = Raphael("canvas", 500, 500);
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": "#f00",
    "stroke-width": 2,
    arc: [100, 100, amount, 100, 100]
}).rotate(180);
我尝试过改变:

["M", xloc, yloc - R],
致:

因此,它将从底部od div开始,但它不起作用

有人帮我修吗?我希望圆始终位于div的中间。例如:如果amount设置为25,则应该是这个样子。


提前谢谢

我怀疑你想要实现的目标可以通过将旋转改为旋转(180100100)来实现,这样你就可以围绕中心而不是其他点旋转。即

var my_arc = archtype.path().attr({
    "stroke": "#f00",
    "stroke-width": 2,
    arc: [100, 100, amount, 100, 100]
}).rotate(180, 100, 100);

哇,真是太棒了。谢谢!我不知道旋转函数接受的参数超过1个。再次感谢!
var my_arc = archtype.path().attr({
    "stroke": "#f00",
    "stroke-width": 2,
    arc: [100, 100, amount, 100, 100]
}).rotate(180, 100, 100);