HTML、CSS——制作手机充电特效

HTML、CSS——制作手机充电特效

尽管前端学习的第一阶段已经结束,接下了要全速开启js,vue,react阶段,练习CSS的次数必然会减少,现在还是能多练一点就多练一点

今天带来是是用CSS制作手机充电特效,用到了动画——animation

在这里插入图片描述
首先确定结构

见图
在这里插入图片描述
在一个box盒子里创建两个小盒子,一个用来显示数字,一个用来创建其他特效元素

HTML

<!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>手机充电特效</title>
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <div class="box">
        <div class="number">98.9%</div>
        <div class="contrast">
            <div class="bubble"></div>
            <div class="bubble"></div>
            <div class="bubble"></div>
            <div class="bubble"></div>
            <div class="bubble"></div>
            <div class="bubble-home"></div>
            <div class="circle"></div>
        </div>
    </div>
</body>

</html>

CSS

* {
    margin: 0;
    padding: 0;
}

body {
    height: 100vh;
    background: #000;
}

.box {
    width: 800px;
    height: 100%;
    margin: 0 auto;
    /* 相对定位 */
    position: relative;
}

/* 充电百分百的文字 */
.number {
    color: #fff;
    position: absolute;
    z-index: 1;
    width: 200px;
    height: 200px;
    line-height: 200px;
    text-align: center;
    font-size: 30px;
    top: 25%;
    left: 50%;
    margin-left: -100px;
}

/* 泡泡 */
.contrast {
    width: 100%;
    height: 100%;
    background-color: #000;
    position: relative;
    /* 设置对比度 */
    filter: contrast(15);

    /* 动画 */
    animation: hueRotate 5s linear infinite;
}

@keyframes hueRotate {
    0% {
        /*contrast是设置对比度  huerotate是设置颜色滤镜 通过设置度数来改变颜色  */
        filter: contrast(15) hue-rotate(0);
    }

    100% {
        filter: contrast(15) hue-rotate(360deg);
    }
}

.circle {
    width: 300px;
    height: 300px;
    position: absolute;
    top: 20%;
    left: 50%;
    margin-left: -150px;
    /* 设置模糊度,配合上面的 contrast 可以产生粘滞的效果*/
    filter: blur(8px);

    animation: circleRotate 5s linear infinite;
}

.circle::before {
    content: '';
    width: 200px;
    height: 200px;
    background-color: cyan;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 42% 38% 63% 49% / 45%;
}

/* 中心圈的黑色 */
.circle::after {
    content: '';
    width: 178px;
    height: 178px;
    background-color: #000;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
}

/* 圆的旋转动画 */
@keyframes circleRotate {
    0%{
        transform: rotate(0);
    }
    100%{
        transform: rotate(360deg);
    }
}
/* 下面泡泡群 */
.bubble-home {
    width: 100px;
    height: 40px;
    background-color: cyan;
    position: absolute;
    left: 50%;
    bottom: 0;
    margin-left: -50px;
    border-radius: 100px 100px 0 0;
    /* 模糊 */
    filter: blur(8px);
}

.bubble {
    width: 20px;
    height: 20px;
    background: cyan;
    border-radius: 100%;
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    z-index: 2;
    filter: blur(5px);
    /* 动画 */
    animation: bubbleUp 5s ease-in-out infinite;
}

.bubble:nth-child(1) {
    width: 20px;
    height: 20px;
    left: 50%;
    animation-duration: 5s;
    animation-delay: 1s;
}

.bubble:nth-child(2) {
    width: 22px;
    height: 22px;
    left: 49%;
    animation-duration: 4s;
    animation-delay: 2s;
}

.bubble:nth-child(3) {
    width: 24px;
    height: 24px;
    left: 47%;
    animation-duration: 3s;
    animation-delay: 3s;
}

.bubble:nth-child(4) {
    width: 18px;
    height: 18px;
    left: 53%;
    animation-duration: 3s;
    animation-delay: 4s;
}

.bubble:nth-child(5) {
    width: 26px;
    height: 26px;
    left: 51%;
    animation-duration: 4s;
    animation-delay: 5s;
}

@keyframes bubbleUp {
    0% {
        bottom: 0;
    }

    100% {
        bottom: calc(80% - 260px);
    }
}

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

玄东林檎

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值