css过渡动画不适用于svg路径的"d"属性更改

cod*_*nky 6 html css animation svg

的jsfiddle

我正在尝试将css过渡应用于svg各种元素. transition: all 2s适用于圆形,但它不适用于路径.

那么"全部"有什么更具体的东西?

编辑:

下面的链接有更多信息动画svg线或路径......似乎css过渡不可能...

你能在SVG属性上使用CSS转换吗?就像一线上的y2?

Hol*_*ill 10

转换只能应用于表示属性,还有一些其他属性,如x,y,cx,cy ...支持的属性列表可以在这里找到http://dev.w3.org/SVG/proposals/css -animation/animation-proposal.html 不幸的是d不是其中之一......

因为浏览器仍然不能可靠地支持,所以您可以使用SMIL动画来获得相同的结果.

var type = true;

setInterval(function() {
    $("#path").attr('from', type ? "M 0 0 L 50 100" : "M 0 0 L 100 50");
    $("#path").attr('to', type ? "M 0 0 L 100 50" : "M 0 0 L 50 100");
    $("#path")[0].beginElement()
    $("#circle").attr('from', type ? "40" : "10");
    $("#circle").attr('to', type ? "10" : "40");
    $("#circle")[0].beginElement()
    type = !type;
}, 1000);
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg>
    <path stroke="#000000" stroke-width="5" d="M 0 0 L 100 50" >  
        <animate id="path" attributeName="d" from="M 0 0 L 100 50" to="M 0 0 L 50 100" dur="1s" fill="freeze"/>
    </path>
    <circle fill="#0000FF" cx="10" cy="50" r="10" >
        <animate id="circle" attributeName="cx" from="10" to="40" dur="1s" fill="freeze"/>
    </circle>
</svg>
Run Code Online (Sandbox Code Playgroud)