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

动画效果

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

  1. 字是从左边平滑过来的,可以使用transformtranslate
  2. 字停下来之后,变颜色而且有稍微的放大,变色用color,放大用transformscale
  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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。