js-components-svg-rect.md 5.9 KB
Newer Older
Z
zengyawen 已提交
1 2 3 4 5
# rect<a name="ZH-CN_TOPIC_0000001127284882"></a>

用于绘制矩形、圆角矩形。

>![](../../public_sys-resources/icon-note.gif) **说明:** 
Z
zengyawen 已提交
6
>该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
Z
zengyawen 已提交
7 8 9 10 11 12 13 14 15 16 17

## 权限列表<a name="section11257113618419"></a>



## 子组件<a name="section9288143101012"></a>

支持animate、animateMotion、animateTransform。

## 属性<a name="section2907183951110"></a>

Z
zengyawen 已提交
18
支持Svg组件[通用属性](js-components-svg-common-attributes.md)和以下属性。
Z
zengyawen 已提交
19

Z
zengyawen 已提交
20
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="23.119999999999997%" id="mcps1.1.6.1.1"><p>名称</p>
Z
zengyawen 已提交
21
</th>
Z
zengyawen 已提交
22
<th class="cellrowborder" valign="top" width="23.119999999999997%" id="mcps1.1.6.1.2"><p>类型</p>
Z
zengyawen 已提交
23
</th>
Z
zengyawen 已提交
24
<th class="cellrowborder" valign="top" width="10.48%" id="mcps1.1.6.1.3"><p>默认值</p>
Z
zengyawen 已提交
25
</th>
Z
zengyawen 已提交
26
<th class="cellrowborder" valign="top" width="7.5200000000000005%" id="mcps1.1.6.1.4"><p>必填</p>
Z
zengyawen 已提交
27
</th>
Z
zengyawen 已提交
28
<th class="cellrowborder" valign="top" width="35.76%" id="mcps1.1.6.1.5"><p>描述</p>
Z
zengyawen 已提交
29 30 31
</th>
</tr>
</thead>
Z
zengyawen 已提交
32
<tbody><tr><td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.1 "><p>id</p>
Z
zengyawen 已提交
33
</td>
Z
zengyawen 已提交
34
<td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.2 "><p>string</p>
Z
zengyawen 已提交
35
</td>
Z
zengyawen 已提交
36
<td class="cellrowborder" valign="top" width="10.48%" headers="mcps1.1.6.1.3 "><p>-</p>
Z
zengyawen 已提交
37
</td>
Z
zengyawen 已提交
38
<td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
39
</td>
Z
zengyawen 已提交
40
<td class="cellrowborder" valign="top" width="35.76%" headers="mcps1.1.6.1.5 "><p>组件的唯一标识。</p>
Z
zengyawen 已提交
41 42
</td>
</tr>
Z
zengyawen 已提交
43
<tr><td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.1 "><p>width</p>
Z
zengyawen 已提交
44
</td>
Z
zengyawen 已提交
45
<td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.2 "><p>&lt;length&gt;|&lt;percentage&gt;</p>
Z
zengyawen 已提交
46
</td>
Z
zengyawen 已提交
47
<td class="cellrowborder" valign="top" width="10.48%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
48
</td>
Z
zengyawen 已提交
49
<td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
50
</td>
Z
zengyawen 已提交
51
<td class="cellrowborder" valign="top" width="35.76%" headers="mcps1.1.6.1.5 "><p>设置矩形的宽度。支持属性动画</p>
Z
zengyawen 已提交
52 53
</td>
</tr>
Z
zengyawen 已提交
54
<tr><td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.1 "><p>height</p>
Z
zengyawen 已提交
55
</td>
Z
zengyawen 已提交
56
<td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.2 "><p>&lt;length&gt;|&lt;percentage&gt;</p>
Z
zengyawen 已提交
57
</td>
Z
zengyawen 已提交
58
<td class="cellrowborder" valign="top" width="10.48%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
59
</td>
Z
zengyawen 已提交
60
<td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
61
</td>
Z
zengyawen 已提交
62
<td class="cellrowborder" valign="top" width="35.76%" headers="mcps1.1.6.1.5 "><p>设置矩形的高度。支持属性动画</p>
Z
zengyawen 已提交
63 64
</td>
</tr>
Z
zengyawen 已提交
65
<tr><td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.1 "><p>x</p>
Z
zengyawen 已提交
66
</td>
Z
zengyawen 已提交
67
<td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.2 "><p>&lt;length&gt;|&lt;percentage&gt;</p>
Z
zengyawen 已提交
68
</td>
Z
zengyawen 已提交
69
<td class="cellrowborder" valign="top" width="10.48%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
70
</td>
Z
zengyawen 已提交
71
<td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
72
</td>
Z
zengyawen 已提交
73
<td class="cellrowborder" valign="top" width="35.76%" headers="mcps1.1.6.1.5 "><p>设置矩形左上角x轴坐标。支持属性动画</p>
Z
zengyawen 已提交
74 75
</td>
</tr>
Z
zengyawen 已提交
76
<tr><td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.1 "><p>y</p>
Z
zengyawen 已提交
77
</td>
Z
zengyawen 已提交
78
<td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.2 "><p>&lt;length&gt;|&lt;percentage&gt;</p>
Z
zengyawen 已提交
79
</td>
Z
zengyawen 已提交
80
<td class="cellrowborder" valign="top" width="10.48%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
81
</td>
Z
zengyawen 已提交
82
<td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
83
</td>
Z
zengyawen 已提交
84
<td class="cellrowborder" valign="top" width="35.76%" headers="mcps1.1.6.1.5 "><p>设置矩形左上角y轴坐标。支持属性动画</p>
Z
zengyawen 已提交
85 86
</td>
</tr>
Z
zengyawen 已提交
87
<tr><td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.1 "><p>rx</p>
Z
zengyawen 已提交
88
</td>
Z
zengyawen 已提交
89
<td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.2 "><p>&lt;length&gt;|&lt;percentage&gt;</p>
Z
zengyawen 已提交
90
</td>
Z
zengyawen 已提交
91
<td class="cellrowborder" valign="top" width="10.48%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
92
</td>
Z
zengyawen 已提交
93
<td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
94
</td>
Z
zengyawen 已提交
95
<td class="cellrowborder" valign="top" width="35.76%" headers="mcps1.1.6.1.5 "><p>设置矩形圆角x方向半径。支持属性动画</p>
Z
zengyawen 已提交
96 97
</td>
</tr>
Z
zengyawen 已提交
98
<tr><td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.1 "><p>ry</p>
Z
zengyawen 已提交
99
</td>
Z
zengyawen 已提交
100
<td class="cellrowborder" valign="top" width="23.119999999999997%" headers="mcps1.1.6.1.2 "><p>&lt;length&gt;|&lt;percentage&gt;</p>
Z
zengyawen 已提交
101
</td>
Z
zengyawen 已提交
102
<td class="cellrowborder" valign="top" width="10.48%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
103
</td>
Z
zengyawen 已提交
104
<td class="cellrowborder" valign="top" width="7.5200000000000005%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
105
</td>
Z
zengyawen 已提交
106
<td class="cellrowborder" valign="top" width="35.76%" headers="mcps1.1.6.1.5 "><p>设置矩形圆角y方向半径。支持属性动画</p>
Z
zengyawen 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
</td>
</tr>
</tbody>
</table>

## 示例<a name="section360556124815"></a>

```
<!-- xxx.hml -->
<div class="container">
  <svg fill="white" width="400" height="400">
    <rect width="100" height="100" x="10" y="20" stroke-width="4" stroke="blue" id="rectId"></rect>
    <rect width="100" height="100" x="150" y="20" stroke-width="4" stroke="blue" rx="10" ry="10"></rect>
    <rect width="100" height="100" x="10" y="130" stroke-width="10" fill="red" stroke="blue" rx="10" ry="10"></rect>
    <rect width="100" height="100" x="150" y="130" stroke-width="10" stroke="red" rx="10" ry="10" stroke-dasharray="5 3" stroke-dashoffset="3"></rect>
    <rect width="100" height="100" x="20" y="270" stroke-width="4" stroke="blue" transform="rotate(-10)"></rect>
  </svg>
</div>
```

![](figures/0.png)