CSS3Loading动画

简介: 前端进阶 css3 小练习 loadding动画实践

病毒肆虐,只能宅在家中,手机越刷越恐慌,不如写点代码吧,在春天来临之前,让我们一边守望,也一边前行。
动画效果如图1:
image

图2
image

<!DOCTYPE html>
<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>loading动画</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
            background-color: #db4d6d;
            display: flex;
            /*水平居中*/
            justify-content: center;
            /*垂直居中*/
            align-items: center;
        }

        .monster {
            width: 110px;
            height: 110px;
            border-radius: 20px;
            /* 圆角 */
            background-color: #e55a54;
            margin: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            /* 嘴巴和眼睛垂直排列 */

            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
            /* 阴影 */
            position: relative;
            /* 定位怪兽角 */
            animation: jumping 0.8s infinite alternate;
        }

        .monster .eye {
            width: 40%;
            height: 40%;
            border-radius: 50%;
            background-color: #fff;
            margin: 10px;
            display: flex;
            justify-content: center;
            align-items: center;

        }

        .monster .eye .eyeBall {
            width: 50%;
            height: 50%;
            border-radius: 50%;
            background-color: #0c4475;
            animation: eyemove 1.6s infinite alternate;
        }

        .monster .mouth {
            width: 32%;
            height: 12px;
            border-radius: 12px;
            background-color: #fff;
        }

        .monster::before,
        .monster::after {
            position: absolute;
            content: '';
            display: block;
            width: 20%;
            height: 10px;
            border-radius: 10px;
            background-color: #fff;
            top: -10px;
            left: 50%;
        }

        .monster::before {
            transform: translateX(-70%) rotate(45deg);
        }

        .monster::after {
            transform: translateX(-30%) rotate(-45deg);
        }

        .monster.blue {
            background-color: #0c4475;
            animation-delay: 0.5s;
        }

        /* 蓝色小怪兽眼睛粉色 */
        .monster.blue .eye .eyeBall,
        .monster.blue .mouth {
            background-color: #db4d6d;
        }

        /* 动画桢 */
        @keyframes jumping {
            50% {
                top: 0;
                box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);

            }

            100% {
                top: -50px;
                box-shadow: 0 120px 20px rgba(0, 0, 0, 0.1);

            }

        }

        @keyframes eyemove {

            0%,
            10% {
                transform: translate(50%);
            }

            100%,
            90% {
                transform: translate(-50%);
            }

        }

        .pageLoading {
            width: 100%;
            height: 100%;
            background-color: #0c4475;
            position: fixed;
            top: 0;
            left: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            transition:opacity 0.5s;
        }

        .pageLoading .loading {
            width: 200px;
            height: 8px;
            background-color: #fff;
            border-radius: 5px;
            margin-top: 50px;
            overflow: hidden;
        }

        .pageLoading .loading .bar {
            width: 100%;
            height: 100%;
            background-color: #db4d6d;

        }
        .pageLoading.complete
        {
            opacity: 0;
        }
        .pageLoading.complete .monster{
            transition: 0.5s;
            transform:scale(0.1) rotateZ(360deg);
        }
        .monsterText
        {
            color: #fff;
        }
    </style>
</head>

<body>
    <h2 class="monsterText">Hello<br> world
    </h2>
    
    <div class="monster ">
        <div class="eye">
            <div class="eyeBall"></div>
        </div>
        <div class="mouth"></div>
    </div>
    <div class="monster blue">
        <div class="eye">
            <div class="eyeBall"></div>
        </div>
        <div class="mouth"></div>
    </div>
    <div class="pageLoading">
        <div class="monster ">
            <div class="eye">
                <div class="eyeBall"></div>
            </div>
            <div class="mouth"></div>
        </div>
        <div class="loading">
            <div class="bar"></div>
        </div>
    </div>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
     <script>
        var per=0;
        var timer;
        timer=setInterval(function()
        {
            $('.bar').css('width',per+'%');
            per+=1;
            if(per>100)
            {
                $('.pageLoading').addClass("complete");
               setTimeout(() => {
                 $('.monsterText').html('<h2>We are Monster</h2>')  
               }, 3000);
                clearInterval(timer);
            }
        },30)
    </script>
</body>

</html>
相关文章
|
7月前
|
前端开发 JavaScript
CSS 过渡和动画
CSS过渡和动画是用于为网页元素添加动态效果的两种重要技术
252 73
|
11月前
|
机器学习/深度学习 前端开发 JavaScript
CSS动画知识点
CSS动画知识点
|
8月前
css3 svg制作404页面动画效果HTML源码
css3 svg制作404页面动画效果HTML源码
142 34
|
10月前
|
移动开发 前端开发 JavaScript
除了 CSS3,还有哪些技术可以实现动画效果?
除了 CSS3,还有哪些技术可以实现动画效果?
308 63
|
10月前
|
JavaScript 前端开发
CSS3 动画和 JavaScript 动画的性能比较
具体的性能表现还会受到许多因素的影响,如动画的复杂程度、浏览器的性能、设备的硬件条件等。在实际应用中,需要根据具体情况选择合适的动画技术。
|
10月前
|
Web App开发 前端开发 JavaScript
如何在不牺牲动画效果的前提下,优化 CSS3 动画的性能?
如何在不牺牲动画效果的前提下,优化 CSS3 动画的性能?
483 58
|
8月前
jQuery+CSS3实现404背景游戏动画源码
jQuery+CSS3实现404背景游戏动画源码
116 22
|
11月前
|
前端开发 搜索推荐 UED
实现 CSS 动画效果的兼容性
【10月更文挑战第16天】实现 CSS 动画效果的兼容性需要对不同浏览器的特性有深入的了解,并采取适当的策略和方法。通过不断的实践和优化,你可以在各种浏览器上创造出流畅、美观且兼容的动画效果,为用户带来更好的体验。在实际开发中,要密切关注浏览器的发展动态,及时掌握最新的兼容性技巧和解决方案,以确保你的动画设计能够在广泛的用户群体中得到良好的呈现。
263 58
|
10月前
纯css3实现的百分比渐变进度条加载动画源码
纯css3实现的百分比渐变进度条加载动画特效源码
177 31
|
9月前
|
Web App开发 移动开发 JavaScript
纯CSS3+SVG实现的节日庆祝五彩纸屑动画效果源码
这是一款基于纯CSS3+SVG实现的节日庆祝五彩纸屑动画效果源码。画面中左下角是一个圆锥形礼炮卡通效果,呈现出节日庆祝时礼花爆破、五彩纸屑纷飞的动画特效。整体动画效果采用纯css3+svg实现,没有引入任何外部图形或js脚本元素。建议使用支持HTML5与css3效果较好的火狐(Firefox)或谷歌(Chrome)等浏览器预览本源码。
179 6

热门文章

最新文章