美文网首页
总结并封装css动画

总结并封装css动画

作者: 前端架构师陈龙威 | 来源:发表于2020-03-25 14:56 被阅读0次

参考资料:1. https://juejin.im/post/5e070cd9f265da33f8653f00 2.

1.加载动画类型1:点点点过渡

点点点加载动画
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
    <style>
        /*main css*/
        .dot-loading{display: flex;margin-top: 200px;}
        .dot-loading>.dot{
            width: 50px;
            height: 50px;
            border-radius: 50%;
            margin-left: 25px;
            margin-right: 25px;
            position: relative;
        }
        .dot-loading>.dot:before{
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: inherit; /*inherit 继承父类*/
            border-radius: inherit;
            animation: kuosan 4s ease-out infinite;
        }
        /*建议使用scss,sass之类的css样式编译,写法会简单很多*/
        /*具体样式可自行调整*/
        .dot-loading>.dot:nth-child(1) {
            background-color: #7ef9ff;
        }
        .dot-loading>.dot:nth-child(2) {
            background-color: #89cff0;
        }
        .dot-loading>.dot:nth-child(3) {
            background-color: #4682b4;
        }
        .dot-loading>.dot:nth-child(4) {
            background-color: #0f52ba;
        }
        .dot-loading>.dot:nth-child(5) {
            background-color: #000080;
        }
        .dot-loading>.dot:nth-child(2):before{
            animation-delay: 0.4s;
        }
        .dot-loading>.dot:nth-child(3):before{
            animation-delay: 0.8s;
        }
        .dot-loading>.dot:nth-child(4):before{
            animation-delay: 1.2s;
        }
        .dot-loading>.dot:nth-child(5):before{
            animation-delay: 1.6s;
        }

        @keyframes kuosan {
            40%{
                transform: scale(1);
                opacity: 1;
            }
            100% {
                transform: scale(2.5);
                opacity: 0;
            }
        }
    </style>
</head>
<body>
<div id="app">
    <dot-loading></dot-loading>
</div>

<script>
    Vue.component('dot-loading', {
        template: `
            <div class="dot-loading">
                <div class="dot" v-for="num in 5" :key="num"></div>
            </div>
        `
    });
    var vm = new Vue({
        el: '#app'
    });

</script>
</body>
</html>

2. 文本展示特效--渐显

渐显
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
    <style>
        /*init css*/
        body {
            display: flex;
            flex-direction: column;
            height: 100vh;
            justify-content: center;
            align-items: center;
            background-color: black;
            /*background-image: linear-gradient(rgba(16, 16, 16, 0.8), rgba(16, 16, 16, 0.8)), url(https://i.loli.net/2019/10/18/buDT4YS6zUMfHst.jpg);*/
            background-size: cover;
        }

        /*main css*/
        .font-animation-landIn {
            display: flex;
            flex-wrap: wrap;
            line-height: 1.8;
            font-size: 50px;
            color: white;
            font-family: Lora, serif;
            white-space: pre;
        }
        .font-animation-landIn>span {
            font-size: 50px;
            animation: font-animation-landIn 0.8s ease-out both;
        }

        @keyframes font-animation-landIn {
            from {
                opacity: 0;
                transform: translateY(-20%);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
    </style>

</head>
<body>
    <div id="app">
        <!--注意,内容的空格也会被算计在内,所以注意好格式-->
        <div class="font-animation-landIn">Ano hi watashitachi mada shirania no Fushigi no mo nogatrao desu</div>
        <div class="font-animation-landIn">召唤师,你相信世界会毁灭吗? 黑暗的终结是光明,死亡的轮回是转生,邪恶的极致便是正义!</div>
    </div>


<script>
    var vm = new Vue({
        el: '#app',
        mounted() {
            initFontAnimationLandIn()
        }
    });

    function initFontAnimationLandIn(animationDelayInterval) {
        // 动画识别--拥有class='font-animation-landIn'的样式的div数组
        let landInTexts = document.querySelectorAll('.font-animation-landIn');
        landInTexts.forEach(function (landInText) {
            // 获取div中的文字内容
            let letters = landInText.textContent.split('');
            // 清除原内容
            landInText.textContent = '';
            letters.forEach(function (letter, index) {
                // 插入增加了动画渲染的span
                let span = document.createElement('span');
                span.textContent = letter;
                span.style.animationDelay = index * (animationDelayInterval? animationDelayInterval: 0.05) + 's';
                landInText.append(span);
            })
        })
    }
    
</script>
</body>
</html>

3. 文字展示特效--两边渐现

两边渐现

相关文章

  • 总结并封装css动画

    参考资料:1. https://juejin.im/post/5e070cd9f265da33f8653f00 ...

  • 2018-08-06 Animate.css 使用

    1.介绍 Animate.css 一个有封装好的动画效果集,跨浏览器css3动画库。效果预览即首页Github地址...

  • Animate.css的初入门

    推荐一个网站最牛前端Animate.css是css动画库,封装了一些动画效果想要使用的话直接在github上下载,...

  • 前端开发入门到实战:动画优雅降级的简单总结

    CSS动画优雅降级的简单总结 CSS动画相关属性 transition:兼容性 transform 3D:兼容性 ...

  • CSS3 动画属性

    概述 思维导图总结一下 CSS3 的动画属性 内容 参考文章 CSS动画简介——阮一峰

  • web前端基础案例-鼠标悬停图文切换效果

    效果知识点: html/css布局思维,定位,浮动详解,css3动画详解,css3选择器详解, 通用样式与封装,企...

  • Js-焦点轮播图

    HTML部分: CSS部分: JS部分: 动画封装到了JS里面,需要用js库。

  • UIView Animation

    今天总结一下UIView动画就是 UiView动画是基于高层API封装进行封装的,对UIView的属性进行修改时候...

  • css 动画总结

    一、2D、3D 转换 (transform) 让元素在一个坐标系统中变形 2D转换 translate(x,y) ...

  • CSS动画总结

    七、CSS动画 1、过渡 transition:过渡,通过过渡可以指定一个属性发生变化时的切换方式。通过过渡可以创...

网友评论

      本文标题:总结并封装css动画

      本文链接:https://www.haomeiwen.com/subject/accayhtx.html