制作一个svg动画图片
时间: 2024-01-28 10:04:36 浏览: 30
好的,以下是一个简单的 SVG 动画图片的代码示例,您可以根据您的需求进行修改:
```html
<svg width="200" height="200">
<rect x="10" y="10" width="30" height="30" fill="#0077be">
<animate attributeName="x" from="10" to="150" dur="1s" repeatCount="indefinite"></animate>
</rect>
<circle cx="100" cy="100" r="30" fill="#00ffea">
<animate attributeName="r" from="0" to="50" dur="1s" repeatCount="indefinite"></animate>
</circle>
<polygon points="130,10 170,40 130,70 90,40" fill="#ffcc00">
<animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0 100 100" to="360 100 100" dur="2s" repeatCount="indefinite"></animateTransform>
</polygon>
</svg>
```
解释一下上面代码的含义:
- `<rect>` 标签用于定义一个矩形,其中 `x` 和 `y` 属性定义了矩形左上角的坐标,`width` 和 `height` 属性定义了矩形的宽度和高度。`fill` 属性定义了矩形的填充颜色。`<animate>` 标签用于定义动画,其中 `attributeName` 属性定义了要进行动画的属性,这里设置为 `x`。`from` 属性定义了动画的起始值,这里设置为 `10`。`to` 属性定义了动画的结束值,这里设置为 `150`。`dur` 属性定义了动画的持续时间,这里设置为 `1s`。`repeatCount` 属性定义了动画的重复次数,这里设置为 `indefinite`,表示无限循环。
- `<circle>` 标签用于定义一个圆形,其中 `cx` 和 `cy` 属性定义了圆心的坐标,`r` 属性定义了圆的半径。`fill` 属性定义了圆的填充颜色。`<animate>` 标签用于定义动画,其中 `attributeName` 属性定义了要进行动画的属性,这里设置为 `r`。`from` 属性定义了动画的起始值,这里设置为 `0`。`to` 属性定义了动画的结束值,这里设置为 `50`。`dur` 属性定义了动画的持续时间,这里设置为 `1s`。`repeatCount` 属性定义了动画的重复次数,这里设置为 `indefinite`,表示无限循环。
- `<polygon>` 标签用于定义一个多边形,其中 `points` 属性定义了多边形各个顶点的坐标。`fill` 属性定义了多边形的填充颜色。`<animateTransform>` 标签用于定义动画,其中 `attributeName` 属性定义了要进行动画的属性,这里设置为 `transform`,表示变换矩阵。`attributeType` 属性定义了属性类型,这里设置为 `XML`。`type` 属性定义了变换类型,这里设置为 `rotate`,表示旋转变换。`from` 属性定义了动画的起始值,这里设置为 `0 100 100`,表示从原始状态开始旋转。`to` 属性定义了动画的结束值,这里设置为 `360 100 100`,表示旋转一周。`dur` 属性定义了动画的持续时间,这里设置为 `2s`。`repeatCount` 属性定义了动画的重复次数,这里设置为 `indefinite`,表示无限循环。
您可以根据需要修改上述代码中的形状、颜色、动画时间等属性,以达到您想要的效果。