Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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 带Jquery的SVG路径动画_Javascript_Jquery_Svg - Fatal编程技术网

Javascript 带Jquery的SVG路径动画

Javascript 带Jquery的SVG路径动画,javascript,jquery,svg,Javascript,Jquery,Svg,我正在尝试设置SVG->Path元素的动画 它就像一个计时器,在10秒内,它应该是零 这是我的SVG代码: <div style="margin:200px"> <svg width="150" height="150" viewBox="0 0 150 150"> <path transform="translate(75, 75) scale(1)" fill="rgba(0,0,0,0.6)" d="M 0, 0 V -75 A 75

我正在尝试设置SVG->Path元素的动画

它就像一个计时器,在10秒内,它应该是零

这是我的SVG代码:

<div style="margin:200px">
    <svg width="150" height="150" viewBox="0 0 150 150">
        <path transform="translate(75, 75) scale(1)" fill="rgba(0,0,0,0.6)" d="M 0, 0 V -75 A 75 75 1 1 1 -0.001 -75 Z"></path>
    </svg>
</div>


但是我不知道如何开始通过jQuery设置动画,这里介绍了如何在不使用jQuery的情况下执行此操作:

<?xml version="1.0" encoding="UTF-8"?>
<svg viewBox="0 0 480 360" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <title>Animates a path</title>  
    <path id="arc" d="M0 0"/>
    <script> 
        var circle = document.getElementById("arc"),
            startangle = -90,
            angle = startangle,
            radius = 100,
            cx = 240,
            cy = 180,
            increment = 5; // make this negative to animate counter-clockwise

        function drawCircle() {
            var radians = (angle/180) * Math.PI,
                x = cx + Math.cos(radians) * radius,
                y = cy + Math.sin(radians) * radius,
                e = circle.getAttribute("d"),
                d = "";

            if(angle == startangle)
                d = "M "+cx + " " + cy + "L "+x + " " + y;
            else
                d = e + " L "+x + " " + y;

            circle.setAttribute("d", d);

            angle += increment;
            if (Math.abs(angle) > (360+startangle*Math.sign(increment)))
                angle = startangle;

            window.requestAnimationFrame(drawCircle);
        }

        drawCircle();
</script>
</svg>

为路径设置动画
var circle=document.getElementById(“弧”),
startangle=-90,
角度=星缠结,
半径=100,
cx=240,
cy=180,
增量=5;//将此设置为负数以逆时针设置动画
函数drawCircle(){
var弧度=(角度/180)*Math.PI,
x=cx+数学余弦(弧度)*半径,
y=cy+Math.sin(弧度)*半径,
e=圆。getAttribute(“d”),
d=“”;
如果(角度==startangle)
d=“M”+cx+“”+cy+“L”+x+“”+y;
其他的
d=e+“L”+x+”+y;
圆.setAttribute(“d”,d);
角度+=增量;
如果(数学绝对值(角度)>(360+startangle*数学符号(增量)))
角度=星缠结;
window.requestAnimationFrame(drawCircle);
}
画圈();

请参阅。

在纯js+DOM中可以找到一个类似的示例,无需jQuery:@ErikDahlström感谢您的回复Erik,我如何使其顺时针运行?您的实时示例仅在firefox中运行。在IE和Chrome中,它没有显示任何内容