svg 动画

本文详细介绍了如何使用SVG和SMILAnimate在HTML中创建路径动画、线性运动和曲线运动,以及旋转动画,提供代码示例,并链接到MDN开发者文档作为参考。
摘要由CSDN通过智能技术生成

在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
    <title>SVG SMIL Animate with Path</title>
</head>
<body>

<!--动画属性-->
<h1>PATH </h1>
<svg width="300px" height="100px">
	<path d="M 100 100 L 300 100 L 100 300 z"
	fill="red" stroke="blue" stroke-width="20"   rx="30" ry="30"/>
</svg>



<!--动画属性-->
<h1>动画属性</h1>
<svg width="300px" height="100px">
    <rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1"/>
    <circle cx="0" cy="50" r="15" fill="blue" stroke="black" stroke-width="1">
        <animate attributeName="cx" from="0" to="100" dur="5s" repeatCount="indefinite"/>
    </circle>
</svg>


<!--旋转动画-->
<h1>旋转动画</h1>
<svg width="300px" height="100px">
    <rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1" rx="30" ry="30"/>
    <rect x="0" y="50" width="15" height="34" fill="blue" stroke="black" stroke-width="1" transform="rotation">
        <!-- Rotate from 0 to 360 degrees, and move from 60 to 100 in the x direction. -->
        <!-- Keep doing this until the drawing no longer exists. -->
        <animateTransform
                attributeName="transform"
                begin="0s"
                dur="20s"
                type="rotate"
                from="0 60 60"
                to="360 100 60"
                repeatCount="indefinite"
        />
    </rect>
</svg>

<h1>路径动画</h1>
<!--线性运动-->
<h2>1.线性运动</h2>
<svg xmlns="http://www.w3.org/2000/svg" width="300px" height="100px">
    <rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1"/>
    <circle cx="0" cy="50" r="15" fill="blue" stroke="black" stroke-width="1">
        <animateMotion path="M 0 0 H 300 Z" dur="3s" repeatCount="indefinite"/>
    </circle>
</svg>
<!--曲线运动-->
<h2>2.曲线运动</h2>
<svg width="300px" height="100px">
    <rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1"/>
    <rect x="0" y="0" width="20" height="20" fill="blue" stroke="black" stroke-width="1">
        <animateMotion path="M 250,80 H 50 Q 30,80 30,50 Q 30,20 50,20 H 250 Q 280,20,280,50 Q 280,80,250,80Z"
                       dur="3s" repeatCount="indefinite" rotate="auto"/>
    </rect>
</svg>


<div>
    <br/>
    <a href="https://developer.mozilla.org/zh-CN/docs/Web/SVG/SVG_animation_with_SMIL">参考MDN开发文档SVG_animation_with_SMIL</a>
</div>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值