我創建了一個組,然後縮放。我只想複製縮放組的形狀而不是其他屬性。特別是我想擺脫轉換後的矩陣。我需要一個獨立於縮放的一個。我不知道是否有可能做到這一點?下面的代碼:svg克隆只有縮放組的形狀
集團汽車:
<svg id="game" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" onload="loadFunction()" >
<!-- Car -->
<g id="exCar" x="50" y="500" transform="" >
<path id="front" d="M 40 500 Q 110 450 110 500 L 40 500" fill="pink" stroke="black" />
<path id="window" d="M 40 500 L 50 530 L 100 530 L 110 500 L 40 500 "stroke="black" />
<path id="sides" d="M 40 500 L 40 580 L 50 560 Q 55 550 50 530 L 40 500 M 110 500 L 110 580 L 100 560 Q 95 550 100 530 L 110 500" fill="pink" stroke="black" />
<path id ="back" d="M 40 580 L 100 560 L 40 580" fill="pink" stroke="blue" />
<path id="wheels" d="M 40 475 L 30 475 L 30 500 L 40 500 z M 110 475 L 120 475 L 120 500 L 110 500 z M 40 545 L 30 545 L 30 570 L 40 570 z" fill="yellow" stroke="black" />
<image id="carpicture2" x="50" y="455" xlink:href="img.jpg"></image>
<text id="carName" x="50" y="575"></text>
</g>
</svg>
按鈕來調用該函數:
<rect x="120" y="600" width="80" height="30" stroke:#FF0066" onclick="cloning()"/>
的功能來複制:
function cloning() {
var newCar = document.getElementById("exCar").cloneNode(true);
newCar.setAttribute("x", 400);
newCar.setAttribute("y", 600);
document.getElementById("game").appendChild(newCar);
alert("!!!!");
};
縮放:
document.getElementById("exCar").setAttribute(
"transform",
"matrix(" + result/100 + ",0,0," + result/100 + ","
+ (x - (result/100 * x)) + "," + (y - (result/100 * y))
+ ")");
(結果是從滑桿計算)
@mihai請不要被睡: ) – Ecrin 2012-04-03 23:19:43
嗨,你能展示你如何在縮放以及? – mihai 2012-04-04 09:37:43
我已編輯縮放 – Ecrin 2012-04-04 10:00:13