纯css3制作无限循环横向滚动的文字广告动画

<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>使用css3制作文字横向无限循环滚动的动画</title>
    <style>
  /**
      设置宽,溢出隐藏
  */
        .marquee-outer-wrapper{
            overflow: hidden;
            width: 80%;
        }
        .marquee-inner-wrapper{
            background: #eee;
            height: 40px;
            font-size: 14px;
            color: red;
            line-height: 40px;
            margin: 0 auto;
            white-space: nowrap;
            position: relative;
        }
  /* 需要将两个文字内容一样的span放在最右边 */
        .marquee-inner-wrapper span{
            position: absolute;
            top: 0;
            left: 100%;
            height: 100%;
        }
  /* 定义第一个span的animation:时长 动画名字 匀速 循环 正常播放 */
        .first-marquee{
            -webkit-animation: 25s first-marquee linear infinite normal;
            animation: 25s first-marquee linear infinite normal;
            padding-right: 70%;
        }
        @keyframes first-marquee {
            0% {
                -webkit-transform: translate3d(0, 0, 0);
                transform: translate3d(0, 0, 0);
            }
     /* 向左移动 */
            100% {
                -webkit-transform: translate3d(-200%, 0, 0);
                transform: translate3d(-200%, 0, 0);
                display: none;
            }
        }
        .second-marquee{
    /* 因为要在第一个span播完之前就得出现第二个span,所以就延迟12s才播放 */
            -webkit-animation: 25s first-marquee linear 12s infinite normal;
            animation: 25s first-marquee linear 12s infinite normal;
            padding-right: 53%;
        }
        @keyframes second-marquee {
            0% {
                -webkit-transform: translate3d(0%, 0, 0);
                transform: translate3d(0%, 0, 0);
            }
            100% {
                -webkit-transform: translate3d(-200%, 0, 0);
                transform: translate3d(-200%, 0, 0);
                display: none;
            }
        }
    </style>
</head>
<body>
    <div class="marquee-outer-wrapper">
        <div class="marquee-inner-wrapper">
            <span class="first-marquee">使用css3制作文字横向无限循环滚动的动画使用css3制作文字横向无限循环滚动的动画使用css3制作文字横向无限循环滚动的动画</span>
            <span class="second-marquee">使用css3制作文字横向无限循环滚动的动画使用css3制作文字横向无限循环滚动的动画使用css3制作文字横向无限循环滚动的动画</span>
        </div>
    </div>
</body>
</html>
posted @ 2018-07-16 14:35  端九九-  阅读(13902)  评论(1编辑  收藏  举报