我在我的專案中使用 SVG.js 庫,我試圖 在 x 方向移動一個包含一些和一個元素rect的text組:use
// create symbol, symbol can be anything
const symbol = svg.symbol().circle(10)
//create group with elements
const group = svg.group();
const rect = group.rect();
const text = group.plain('some text');
const symbolUse = svg.use(symbol);
group.add(symbolUse);
//some time later...move group to new x coordinate (can be anything)
group.x(newX)
現在它與所有文本和矩形元素完全兼容。它們按照我希望它們在 x 方向上移動的方式移動。但是 use 元素以某種方式在 x 和 y 方向上移動,它絕對不應該這樣做。


現在這是來自 SVG.js 庫的錯誤,還是我遺漏了有關 use 元素的內容?
uj5u.com熱心網友回復:
你想要的是transform()功能。
請參閱:https ://svgjs.dev/docs/3.0/manipulating/#transforming
var svg = SVG().addTo('body').size(300, 300)
const symbol = svg.symbol().circle(10)
//create group with elements
const group = svg.group();
const rect = group.rect();
const text = group.plain('some text');
const symbolUse = svg.use(symbol);
group.add(symbolUse);
// Move the whole group right by 150 units
group.transform({translateX: 150});
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/[email protected]/dist/svg.min.js"></script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/441110.html
標籤:javascript 打字稿 svg svg.js
