CSS --- 动画练习

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/index.css">
</head>
<body>
    <!-- 云彩图片 -->
    <div class="cloud">
        <img src="./images/yun1.png" alt="">
        <img src="./images/yun2.png" alt="">
        <img src="./images/yun3.png" alt="">
    </div>
     <!-- 伞 -->
    <div class="san">
        <img src="./images/san.png" alt="">
    </div>
    <!-- 鹿和字 -->
    <div class="center">
        <img src="./images/lu.png" alt="">
        <img src="./images/font1.png" alt="">
    </div>
    <!-- 折扣图片 -->
    <div class="zhekou">
        <img src="./images/1.png" alt="">
        <img src="./images/2.png" alt="">
        <img src="./images/3.png" alt="">
        <img src="./images/4.png" alt="">
</body>
</html>
* {
    margin: 0;
    padding: 0;
}
/*  html和body的高度必须都写上  */
html {
    height: 100%;
}

body {
    height: 100%;
    background: url(./../images/f1_1.jpg) no-repeat center 0;

    /* 缩放背景图 */

    /* 图片等比例缩放, 当宽度或高度和盒子尺寸相等, 图片就不再缩放 */
    /* background-size: contain; */

    /* 图片等比例缩放, 图片完全覆盖到整个盒子, 可能会导致图片显示不全 */
    background-size: cover;
}

/* 
1. img 引入图片, 控制位置
2. 定义动画,使用动画
*/

.cloud img {
    position: absolute;
    left: 50%;
    top: 0;
}

.cloud img:nth-child(1) {
    margin-left: -300px;
    top: 20px;
    animation: cloud 1s infinite alternate;
}
.cloud img:nth-child(2) {
    margin-left: 400px;
    top: 100px;
    animation: cloud 1s infinite alternate 0.2s;
}
.cloud img:nth-child(3) {
    margin-left: -550px;
    top: 200px;
    animation: cloud 1s infinite alternate 0.4s;
}

/* 云彩动画 */
@keyframes cloud {
    to {
        transform: translateX(20px);
    }
}

/* 伞的设置 */

.san img{
    position: absolute;
    left: 50%;
    margin-left: -330px;
    top: 90px;
    animation: san 2s infinite alternate; 
}
/* 伞动画 */
@keyframes san {
    to{
        transform: translateY(20px);
    }
}


/* 中间设置 */
.center img{
    position: absolute;
    left: 50%;
    top: 0;
}
.center img:nth-child(1){
    margin-left: 90px;
    top: 100px;
    transform: scale(0.7);
}
.center img:nth-child(2){
    margin-left: -325px;
    top: 230px;
    transform: scale(0.8);
}



/* 折扣设置 */
.zhekou img{
    position: absolute;
    left: 50%;
    bottom: 0;
}

.zhekou img:nth-child(1){
    margin-left: -350px;
    bottom: 60px;
    animation: zhekou 2s infinite alternate;
}
.zhekou img:nth-child(2){
    margin-left: -180px;
    bottom: 60px;
    animation: zhekou 2s infinite alternate 0.2s;
}
.zhekou img:nth-child(3){
    margin-left: -10px;
    bottom: 60px;
    animation: zhekou 2s infinite alternate 0.4s;
}
.zhekou img:nth-child(4){
    margin-left: 160px;
    bottom: 60px;
    animation: zhekou 2s infinite alternate 0.4s;
}
/* 折扣动画 */
@keyframes zhekou {
    to{
        transform: translateY(20px);
    }
}

所使用的图片及素材:
在这里插入图片描述
请添加图片描述
实现的效果是:上面三朵云左右移动、热气球上下移动、下面的四个折扣情况收下移动,中间的鹿和文字进行了缩放
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虾小眠0526

你们的鼓励是我前进的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值