SVG.js 元素操作整理(一)

來源:互聯網
上載者:User

標籤:images   console   引用   clip   分享   fill   svg   透明度   擷取   

一、屬性操作Attributes

var draw = SVG(‘svg1‘).size(300, 300);//attr() 屬性操作//設定屬性的值var rect = draw.rect(100, 100);rect.attr(‘x‘, 50).attr(‘y‘, 50);rect.attr({    fill: ‘#f06‘,    ‘fill-opacity‘: 0.5,    stroke: ‘#000‘,    ‘stroke-width‘: 10});//刪除屬性rect.attr(‘fill‘, null);//擷取屬性的值var x = rect.attr(‘x‘);console.info(x);var attributes = rect.attr();console.info(attributes);

屬性內容如下:

二、位置操作Positioning

var draw = SVG(‘svg1‘).size(300, 300);//Positioning 位置操作var rect = draw.rect(100, 100);var circle = draw.circle(100, 100).fill(‘#f06‘);//1.使用attr()設定位置rect.attr({ x: 50, y: 50 });circle.attr({ cx: 100, cy: 150 });//2.使用 x()/y() cx()/cy() dx()/dy() 擷取或設定位置//x()/y()   x軸、y軸相對父節點擷取或設定位置//cx()/cy() x軸、y軸擷取或移動中心//dx()/dy() x軸、y軸相對於當前位置的移動rect.x(50).y(50);rect.cx(50).cy(50);circle.cx(100).cy(100);rect.dx(50).dy(50);//3.move()/dmove() ---推薦使用的方式,如果僅指定一個值,則只是在x軸方向移動circle.dmove(100, 100); //相對當前位置,目前的位置上再次移動circle.move(100, 100);//相對父節點左上方//4.center() 設定圓心的位置//circle.center(100,100);console.info(circle.x());console.info(circle.cx());

三、大小操作Resizing

var draw = SVG(‘svg1‘).size(300, 300);//Resizeing 擷取或設定元素大小var rect = draw.rect(100, 100).fill(‘#f07‘);var circle = draw.circle(100);//1.size() 設定大小rect.size(200); //指定一個值,則寬度和高度相同rect.size(200, 100);//2.width() 擷取或設定寬度console.info(rect.width());rect.width(200);//3.height() 擷取或設定高度console.info(rect.height());rect.height(200);//4.raduis() 擷取或設定圓角//circle.radius(50); //設定半徑circle.radius(30, 50); //設定半徑,對於圓,只使用第一個參數,對於橢圓可以設定兩個參數rect.radius(20); //設定圓角

四、填充、描邊、透明度操作 Syntatic

var draw = SVG(‘svg1‘).size(300, 300);//Syntactic sugar 填充,描邊、透明度var rect = draw.rect(100, 100);//-----fill() 填充// //指定填充顏色和透明度rect.fill({color:‘#f06‘,opacity:0.6});// //指定填充顏色rect.fill(‘red‘);// //指定填充背景圖rect.fill(‘../scripts/36.jpg‘);// //指定背景圖片大小rect.fill(draw.image(‘../scripts/36.jpg‘, 30, 30));//-----stroke() 描邊rect.move(100, 100);//使用json對象,指定顏色,寬度,透明度rect.stroke({ color: ‘#f06‘, opacity: 0.6, width: 20 });//指定邊框顏色rect.stroke(‘yellow‘);// 指定邊框背景圖片rect.stroke(‘../scripts/tool.png‘);// 指定邊框圖片大小rect.stroke(draw.image(‘../Scripts/tool.png‘, 20, 20));//-----opacity() 透明度設定rect.opacity(0.5);

更多:

SVG.js 引用擷取整理

SVG.js Marker標記和自訂標籤

SVG.js Mask覆蓋和ClipPath裁剪

SVG.js 元素操作整理(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.