2

SVGに飛び込むのはこれが初めてです。cssまたはjavascript/jqueryなしで、このグループを無期限に360回転させることは可能ですか? これまでのところ、左上隅で回転させていますが、中央に配置する方法がわかりません。

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
<svg width="576" height="576" viewBox="0 0 288 288" xmlns="http://www.w3.org/2000/svg" version="1.1">
<g id="seed" transform="translate(144,144)" stroke-width="2" stroke="black" fill="none" >
<circle cx="0" r="64" />
<circle cx="64" r="64" />
<circle cx="64" r="64" transform="rotate(60)" />
<circle cx="64" r="64" transform="rotate(120)" />
<circle cx="64" r="64" transform="rotate(180)" />
<circle cx="64" r="64" transform="rotate(240)" />
<circle cx="64" r="64" transform="rotate(300)" />
<circle cx="0" r="128" />
<animateTransform attributeType="xml" attributeName="transform" type="rotate" values="0 0 0; 360 0 0" dur="5s" repeatCount="indefinite" />
</g>
</svg>
4

2 に答える 2

0

PaEDIT: 残念ながら、あなたはおそらく JavaScript のことを言っているのでしょう。

JavaScript と getBBox() と呼ばれる便利な SVG メソッドを使用して中心を計算できます。

SVG要素の中心を返すメソッドなので、あなたも可能です。わかりましたコード

 var svg = {    
 getCenterPosition:  function(elem) {

        // use the native SVG interface to get it's boundingBox
        var bbox                = elem.getBBox();
        // return the center of the bounding box
        return {
            px: (bbox.x + bbox.width / 2).toFixed(2),
            py: (bbox.y + bbox.height / 2).toFixed(2)
        };
    }
}

svg.getCenterPosition(yourGElementAsParameter); 中心座標を返します。(Web開発者コンソールまたはFirebugなど)次に、これらの座標を属性に設定できますが、ビューボックスなどを変更しないでください。現在、中心を中心に回転します。

于 2013-07-29T19:18:16.160 に答える