HTML5中利用animation属性实现风车动画案例

这里写图片描述

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        /* 设置风车旋转函数 */
        @keyframes zhuan {
            from {
                transform: rotate(0deg);
            }
            to {
                transform: rotate(360deg);
            }
        }
        body {
            background-image: url("images/grass.png");
        }
        /* 定义风车的位置,并为其添加di 动画函数*/
        .box1 {
            position: absolute;
            left: 353px;
            top: 230px;
            float: left;
            animation: zhuan 4s infinite linear;
        }
        .box2 {
            position: absolute;
            left: 931px;
            top: 618px;
            float: left;
            animation: zhuan 1s infinite linear;
        }
        .box3 {
            position: absolute;
            left: 1259px;
            top: 479px;
            float: left;
            animation: zhuan 2s infinite linear;
        }
    </style>
</head>
<body>
    <div class="box1">
        <img src="images/shan.png" alt="fengche" id="zhuan" width="450px">
    </div>
    <div class="box2">
        <img src="images/shan.png" alt="fengche" id="zhuan" width="200px">
    </div>
    <div class="box3">
        <img src="images/shan.png" alt="fengche" id="zhuan" width="300px">
    </div>
</body>
</html>
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在HTML,`animation`属性是CSS动画的一种方式,它可以让元素在指定的时间内从一种样式过渡到另一种样式。该属性通常与`@keyframes`规则一起使用,`@keyframes`规则指定了动画的关键帧,即元素在动画过程应该出现的样式。 `animation`属性有以下几个可用值: - `animation-name`: 指定要应用的`@keyframes`规则的名称。 - `animation-duration`: 指定动画的持续时间,以秒或毫秒为单位。 - `animation-timing-function`: 指定动画的时间函数,即元素在动画过程的加速度曲线。 - `animation-delay`: 指定动画开始之前的延迟时间,以秒或毫秒为单位。 - `animation-iteration-count`: 指定动画应该重复多少次,或是否应该无限重复。 - `animation-direction`: 指定动画应该向前播放、向后播放、交替播放还是反向播放。 - `animation-fill-mode`: 指定动画在播放前和播放后如何应用样式。 - `animation-play-state`: 指定动画是否正在运行或已暂停。 以下是一个示例,演示如何使用`animation`属性: ```html <style> .box { width: 100px; height: 100px; background-color: red; animation-name: move; animation-duration: 2s; animation-timing-function: ease-in-out; animation-delay: 1s; animation-iteration-count: infinite; animation-direction: alternate; animation-fill-mode: forwards; animation-play-state: running; } @keyframes move { 0% { transform: translateX(0); } 50% { transform: translateX(100px); } 100% { transform: translateX(0); } } </style> <div class="box"></div> ``` 此示例将创建一个具有无限次交替播放的动画,该动画会使一个红色正方形元素在X轴上来回移动。动画将在1秒后开始,持续2秒,采用ease-in-out时间函数,并在动画结束时保留最终位置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值