美文网首页css
从左滑过来且中途变色放大的文字动画

从左滑过来且中途变色放大的文字动画

作者: Lia代码猪崽 | 来源:发表于2019-02-16 16:08 被阅读0次
    动画效果

    这个动画效果可以拆分三几步:

    1. 字是从左边平滑过来的,可以使用transformtranslate
    2. 字停下来之后,变颜色而且有稍微的放大,变色用color,稍微放大用translatescale
    3. 字停下来距离动画完成过程很短

    完整代码

     <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>CSS Text animation Left Color</title>
        <style>
            .container {
                margin: 0;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
                font-size: 50px;
                /*color: #24a8e6;*/
                color: #B10F81;
                font-weight: bold;
            }
            .left-flip span{
                /*行内块级才能 transform 属性*/
                display: inline-block;
                animation: revolveScale .4s forwards;
                opacity: 0;
            }
            @keyframes revolveScale {
                0% {
                    transform: translate(-150px, 0) rotate(0) scale(1);
                    color: #B10F81;
                    opacity: 0;
                }
                60% {
                    transform: translate(-20px, 0) rotate(0) scale(1);
                    color: #B10F81;
                }
                99% {
                    transform: translate(0) rotate(0) scale(1.2);
                    color: #24a8e6;
                }
                100% {
                    transform: translate(0) rotate(0) scale(1);
                    opacity: 1;
                }
            }
            .left-flip span:nth-of-type(2) {
                animation-delay: .1s;
            }
            .left-flip span:nth-of-type(3) {
                animation-delay: .2s;
            }
            .left-flip span:nth-of-type(4) {
                animation-delay: .3s;
            }
            .left-flip span:nth-of-type(5) {
                animation-delay: .4s;
            }
            .left-flip span:nth-of-type(6) {
                animation-delay: .5s;
            }
            .left-flip span:nth-of-type(7) {
                animation-delay: .6s;
            }
            .left-flip span:nth-of-type(8) {
                animation-delay: .7s;
            }
            .left-flip span:nth-of-type(9) {
                animation-delay: .8s;
            }
            .left-flip span:nth-of-type(10) {
                animation-delay: .9s;
            }
            .left-flip span:nth-of-type(11) {
                animation-delay: 1s;
            }
            /*按钮样式*/
            .repeat {
                padding: 5px;
                font-size: 12px;
                text-decoration: none;
                color: rebeccapurple;
                border: 1px solid #24a8e6;
            }
        </style>
    </head>
    <body>
    <div class="container left-flip" >
        <span>H</span>
        <span>e</span>
        <span>l</span>
        <span>l</span>
        <span>o</span>
        &nbsp;
        <span>W</span>
        <span>o</span>
        <span>r</span>
        <span>l</span>
        <span>d</span>
        <span>!</span>
        <a class="repeat" href="javascript:void(0);">Repeat Animation</a>
    </div>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
    <script>
        $('.repeat').click(function () {
            var $container = $('.container')
            $container.removeClass('left-flip')
            setTimeout(function () {
                $container.addClass('left-flip')
            }, 20)
        })
    </script>
    </body>
    </html>
    
    

    参考资料

    http://www.templatesy.com/Article/562.html

    相关文章

      网友评论

        本文标题:从左滑过来且中途变色放大的文字动画

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