麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 擴展 > SVG > 正文

svg DOM的一些js操作

2024-09-06 19:57:08
字體:
供稿:網(wǎng)友
這是第一個實例,其中講了如何新建svg,添加元素,保存svg document,查看svg.
下面將附上常用一些元素的添加方法:(為js的,但基本上跟java中操作一樣,就是類名有點細微差別)

Circle

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    var shape = svgDocument.createElementNS(svgns, "circle");    shape.setAttributeNS(null, "cx", 25);    shape.setAttributeNS(null, "cy", 25);    shape.setAttributeNS(null, "r",  20);    shape.setAttributeNS(null, "fill", "green");        svgDocument.documentElement.appendChild(shape);}

Ellipse

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    var shape = svgDocument.createElementNS(svgns, "ellipse");    shape.setAttributeNS(null, "cx", 25);    shape.setAttributeNS(null, "cy", 25);    shape.setAttributeNS(null, "rx", 20);    shape.setAttributeNS(null, "ry", 10);    shape.setAttributeNS(null, "fill", "green");        svgDocument.documentElement.appendChild(shape);}

Line

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    var shape = svgDocument.createElementNS(svgns, "line");    shape.setAttributeNS(null, "x1", 5);    shape.setAttributeNS(null, "y1", 5);    shape.setAttributeNS(null, "x2", 45);    shape.setAttributeNS(null, "y2", 45);    shape.setAttributeNS(null, "stroke", "green");        svgDocument.documentElement.appendChild(shape);}

Path

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    var shape = svgDocument.createElementNS(svgns, "path");    shape.setAttributeNS(null, "d", "M5,5 C5,45 45,45 45,5");    shape.setAttributeNS(null, "fill", "none");    shape.setAttributeNS(null, "stroke", "green");        svgDocument.documentElement.appendChild(shape);}

Polygon

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    shape = svgDocument.createElementNS(svgns, "polygon");    shape.setAttributeNS(null, "points", "5,5 45,45 5,45 45,5");    shape.setAttributeNS(null, "fill", "none");    shape.setAttributeNS(null, "stroke", "green");        svgDocument.documentElement.appendChild(shape);}

Polyline

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    shape = svgDocument.createElementNS(svgns, "polyline");    shape.setAttributeNS(null, "points", "5,5 45,45 5,45 45,5");    shape.setAttributeNS(null, "fill", "none");    shape.setAttributeNS(null, "stroke", "green");        svgDocument.documentElement.appendChild(shape);}

Rectangle

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    var shape = svgDocument.createElementNS(svgns, "rect");    shape.setAttributeNS(null, "x", 5);    shape.setAttributeNS(null, "y", 5);    shape.setAttributeNS(null, "width",  40);    shape.setAttributeNS(null, "height", 40);    shape.setAttributeNS(null, "fill", "green");        svgDocument.documentElement.appendChild(shape);}

Rounded Rectangle

var svgns = "http://www.w3.org/2000/svg";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    var shape = svgDocument.createElementNS(svgns, "rect");    shape.setAttributeNS(null, "x", 5);    shape.setAttributeNS(null, "y", 5);    shape.setAttributeNS(null, "rx", 5);    shape.setAttributeNS(null, "ry", 5);    shape.setAttributeNS(null, "width",  40);    shape.setAttributeNS(null, "height", 40);    shape.setAttributeNS(null, "fill", "green");        svgDocument.documentElement.appendChild(shape);}

Use

var svgns   = "http://www.w3.org/2000/svg";var xlinkns = "http://www.w3.org/1999/xlink";function makeShape(evt) {    if ( window.svgDocument == null )        svgDocument = evt.target.ownerDocument;    var svgRoot = svgDocument.documentElement;    var defs = svgDocument.createElementNS(svgns, "defs");        var rect = svgDocument.createElementNS(svgns, "rect");    rect.setAttributeNS(null, "id", "rect");    rect.setAttributeNS(null, "width", 15);    rect.setAttributeNS(null, "height", 15);    rect.setAttributeNS(null, "style", "fill: green");    defs.appendChild(rect);        var use1 = svgDocument.createElementNS(svgns, "use");    use1.setAttributeNS(null, "x", 5);    use1.setAttributeNS(null, "y", 5);    use1.setAttributeNS(xlinkns, "xlink:href", "#rect");        use2 = svgDocument.createElementNS(svgns, "use");    use2.setAttributeNS(null, "x", 30);    use2.setAttributeNS(null, "y", 30);    use2.setAttributeNS(xlinkns, "xlink:href", "#rect");        svgRoot.appendChild(defs);    svgRoot.appendChild(use1);    svgRoot.appendChild(use2);}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 91久久99热青草国产 | 久久蜜桃精品一区二区三区综合网 | 色999久久久精品人人澡69 | 黄a大片 | 免费久久精品 | 精品中文字幕久久久久四十五十骆 | 成人短视频在线播放 | 99这里精品 | 成人毛片网 | 一级美女大片 | av在线免费电影 | av在线影片 | 国产精品观看在线亚洲人成网 | 国产三级精品最新在线 | 久久久久久久久久美女 | 亚洲国产精品一区二区久久 | 亚洲一级成人 | 少妇的肉体2无删减版 | 美女露100%无遮挡 | 美国一级黄色毛片 | 免费a级黄色片 | 国产精品美女久久久免费 | 黄色一级电影网 | 天天操很很操 | 精品一区二区在线观看视频 | 一级电影免费在线观看 | 4p一女两男做爰在线观看 | 久久毛片| 国产成人在线播放视频 | 国产精品久久久免费观看 | 99精品视频免费看 | 成人性生活视频在线观看 | 精品一区二区三区毛片 | 久久精品女人天堂av | 欧美日韩国产中文字幕 | 久草在线综合 | 综合网日日天干夜夜久久 | 717影院理论午夜伦八戒秦先生 | 91色琪琪电影亚洲精品久久 | 成人毛片av在线 | 九九精品视频免费 |