88svg子标签(示例)

母标签<svg>有下列子标签:矩形 <rect>、圆形 <circle>、椭圆 <ellipse>、线 <line>、路径 <path>、 多边形 <polygon>、折线 <polyline>;母子标签之间还可以套进组标签<g></g>、复用标签<defs></defs>;套后标签层级关系为<svg><defs><g><reac></reac><circle></circle>......</g></defs></svg>。
1.矩形 <rect>
x 属性定义矩形的左侧位置(例如,x="0" 定义矩形到浏览器窗口左侧的距离是 0px)
y 属性定义矩形的顶端位置(例如,y="0" 定义矩形到浏览器窗口顶端的距离是 0px)
CSS 的 fill-opacity 属性定义填充颜色透明度(合法的范围是:0 - 1)
CSS 的 stroke-opacity 属性定义笔触颜色的透明度(合法的范围是:0 - 1)

```html:run
<svg width="100%" height="100%">
<rect x="20" y="20" width="250" height="100" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9"/>
</svg>
```


2.圆形 <circle>
cx 和 cy 属性定义圆点的 x 和 y 坐标。
如果省略 cx 和 cy,圆的中心会被设置为 (0, 0)
r 属性定义圆的半径。
**html 代码**

```html:run
<svg width="100%" height="100%">
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
</svg>
```


3.椭圆 <ellipse>
cx 属性定义圆点的 x 坐标
cy 属性定义圆点的 y 坐标
rx 属性定义水平半径
ry 属性定义垂直半径
**html 代码**

```html:run
<svg width="100%" height="100%">
<ellipse cx="300" cy="150" rx="200" ry="80" style="fill:rgb(200,100,50);stroke:rgb(0,0,100);stroke-width:2"/>
</svg>
```


4.线 <line>
x1 属性在 x 轴定义线条的开始
y1 属性在 y 轴定义线条的开始
x2 属性在 x 轴定义线条的结束
y2 属性在 y 轴定义线条的结束
**html 代码**

```html:run
<svg width="100%" height="100%" >
<line x1="0" y1="0" x2="300" y2="300" style="stroke:rgb(99,99,99);stroke-width:2"/>
</svg>
```


5.路径 <path>
定义了一条路径,它开始于位置 250 150,到达位置 150 350,然后从那里开始到 350 350,最后在 250 150 关闭路径。
**html 代码**

```html:run
<svg width="100%" height="100%">
<path d="M250 150 L150 350 L350 350 Z" />
</svg>
```


6.多边形 <polygon>
points 属性定义多边形每个角的 x 和 y 坐标
**html 代码**

```html:run
<svg width="100%" height="100%">
<polygon points="220,100 300,210 170,250" style="fill:#cccccc; stroke:#000000;stroke-width:1"/>
</svg>
```


7.折线 <polyline>
标签用来创建仅包含直线的形状。

```html:run
<svg width="100%" height="100%">
<polyline points="0,0 0,20 20,20 20,40 40,40 40,60" style="fill:white;stroke:red;stroke-width:2"/>
</svg>
```

转载于:https://www.cnblogs.com/gushixianqiancheng/p/10967135.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用SVG制作一个横向树形结构,可以按以下步骤进行: 1. 首先,使用Vue创建一个组件,命名为Tree。 2. 在Tree组件中,使用SVG标签来绘制树形结构。SVG是一种可缩放矢量图形格式,可以通过代码来描述图形,非常适合用来绘制图形化的数据结构。 3. 在SVG标签中,使用<g>标签来组合多个图形元素,形成一个组合。 4. 使用<path>标签来绘制树形结构中的线条。可以使用<path>标签的d属性来定义绘制路径,例如M x1 y1 L x2 y2表示从点(x1,y1)到点(x2,y2)绘制一条直线。 5. 使用<circle>标签来绘制树形结构中的节点。可以使用<circle>标签的cx和cy属性来定义圆心坐标,r属性来定义半径。 6. 在Tree组件中,使用props属性来接收传入的树形结构数据。可以使用递归的方式,将树形结构数据中的每个节点都绘制出来。 下面是一个简单的示例代码: ```html <template> <svg> <g> <path :d="line.path" stroke="black" fill="none" /> <circle :cx="node.x" :cy="node.y" :r="node.r" fill="red" /> <text :x="node.x" :y="node.y">{{ node.value }}</text> </g> <tree v-for="child in node.children" :node="child" :key="child.id" /> </svg> </template> <script> export default { name: "Tree", props: { node: { type: Object, required: true, }, }, computed: { line() { const { x, y, width, height } = this.node; const path = `M ${x} ${y + height / 2} H ${x + width}`; return { path }; }, }, components: { Tree, }, }; </script> ``` 在这个示例中,我们定义了一个Tree组件,接收一个node属性作为参数。每个Tree组件都会绘制一个节点和一条线条,然后递归地绘制节点。在计算属性line中,我们使用节点的位置和尺寸信息来计算线条的路径。在模板中,我们使用<g>标签来组合多个图形元素,使用v-for指令来遍历节点,并递归地渲染Tree组件。 当我们使用这个Tree组件时,可以将树形结构数据作为参数传入: ```html <template> <tree :node="treeData" /> </template> <script> import Tree from "./Tree.vue"; export default { name: "App", components: { Tree, }, data() { return { treeData: { id: 1, value: "root", children: [ { id: 2, value: "child 1", children: [ { id: 4, value: "grandchild 1", children: [], }, { id: 5, value: "grandchild 2", children: [], }, ], }, { id: 3, value: "child 2", children: [], }, ], }, }; }, }; </script> ``` 这样就可以在Vue中使用SVG绘制出一个横向树形结构了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值