纯css实现水平无限滚动--适应PC和移动端

本文通过具体的HTML和CSS代码展示了两种不同的动画效果:水平无限滚动的文字和上下无限抖动的文字。这两种效果均使用了关键帧动画实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、HTML

<style type="text/css">
            * {
                margin: 0;
                padding: 0;
                list-style: none;
            }
            /*水平无限滚动css*/
            #container {
                width: 100%;
                height: 35px;
                margin: 10px auto;
                overflow: hidden;
                position: relative;
                border: 1px solid red;
                box-sizing: border-box;
            }

            #container ul {
                width: 100%;
                right: -100%;
                top: 0;
                position: absolute;
                -webkit-animation: scollLeft 10s linear 0s infinite;
            }

            #container ul li {
                float: left;
                line-height: 35px;
                width: 10%;
                text-align: center;
                box-sizing: border-box;
            }

            @-webkit-keyframes scollLeft {
                from {
                    right: -100%;
                }
                to {
                    right: 100%;
                }
            }

            @keyframes scollLeft {
                from {
                    right: -100%;
                }
                to {
                    right: 100%;
                }
            }

            @-moz-keyframes scollLeft {
                from {
                    right: -100%;
                }
                to {
                    right: 100%;
                }
            }

            @-o-keyframes scollLeft {
                from {
                    right: -100%;
                }
                to {
                    right: 100%;
                }
            }
            /*上下无限抖动css*/
            .jump span {
                float: left;
                position: relative;
            }

            .jump span:nth-child(1) {
                -webkit-animation: jump 1s linear 0s infinite alternate;
            }

            .jump span:nth-child(2) {
                -webkit-animation: jump 1s linear 0.2s infinite alternate;
            }

            .jump span:nth-child(3) {
                -webkit-animation: jump 1s linear 0.4s infinite alternate;
            }

            .jump span:nth-child(4) {
                -webkit-animation: jump 1s linear 0.6s infinite alternate;
            }

            .jump span:nth-child(5) {
                -webkit-animation: jump 1s linear 0.8s infinite alternate;
            }

            @-webkit-keyframes jump {
                0% {
                    top: 0px;
                    color: red;
                }
                50% {
                    top: -10px;
                    color: green;
                }
                100% {
                    top: 10px;
                    color: blue;
                }
            }

            @keyframes jump {
                0% {
                    top: 0px;
                    color: red;
                }
                50% {
                    top: -10px;
                    color: green;
                }
                100% {
                    top: 10px;
                    color: blue;
                }
            }

            @-moz-keyframes jump {
                0% {
                    top: 0px;
                    color: red;
                }
                50% {
                    top: -10px;
                    color: green;
                }
                100% {
                    top: 10px;
                    color: blue;
                }
            }
        </style>
    </head>

    <body>
        <div id="container">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
                <li>6</li>
                <li>7</li>
                <li>8</li>
                <li>9</li>
                <li>10</li>
            </ul>
        </div>

        <h2 class="jump">  
            <span></span>  
            <span></span>  
            <span></span>  
            <span></span>  
            <span></span>  
        </h2>
    </body>

二、效果图

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值