使用svg.js時(shí),關(guān)于svg元素的集中對(duì)齊方式

svg.js 的set可以操作每個(gè)set組合里面的子元素
setGroupAlign (type) {

????????let box = this.group.set.bbox();

????????let last = this.draw.last();

????????// console.log(box)

????????switch(type){

????????????case 'left':

//? ? 保持左對(duì)齊

????????????????this.group.set.x(box.x)?

????????????break;

????????????case 'right':

// 右對(duì)齊會(huì)有元素偏移出去,

????????????????this.group.set.members.forEach(g =>{

????????????????????let width = g.bbox().width

// 移動(dòng)的時(shí)候需要減去當(dāng)前元素的寬度

????????????????????g.x(box.x2-width)

????????????????})

????????????break;

????????????case 'center':

// 統(tǒng)一set里面的中心點(diǎn),居中對(duì)齊

????????????????this.group.set.cx(box.cx, box.cy)

????????????break;

????????????case 'middle':

????????????????this.group.set.cy(box.cy, box.cy)

????????????break;

????????????case 'top':

????????????????this.group.set.y(box.y)

????????????break;

????????????case 'bottom':

//同右對(duì)齊一樣的原理

????????????????this.group.set.members.forEach(g =>{

????????????????????let width = g.bbox().height

????????????????????g.y(box.x2-width)

????????????????})

????????????break;

????????}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容