css3动画轮播图

css3动画轮播图

核心:

1.起始位置是负的一轮长度(即四个小li为一轮)。

2.移动最终位置是0,即从负的一轮长度移到起点即可。

3.鼠标触碰位置暂停动画,属性animation-play-state: paused;。

效果图:
在这里插入图片描述

代码如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>轮播</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        border: 0;
      }
      .box {
        margin: 200px;
        width: 400px;
        height: 50px;
        box-sizing: border-box;
        border: 1px solid #000;
        overflow: hidden;
      }
      .box ul {
        list-style: none;
        width: 1400px;
        transform: translateX(-400px);
        animation: move 6s linear infinite;
      }
      .box:hover ul {
        animation-play-state: paused;
      }
      .box ul li {
        float: left;
        width: 100px;
        height: 50px;
        border: 1px solid rgb(251, 251, 251);
      }
      .box ul li:nth-child(n) {
        background: url(img/31.png);
        background-size: 100px 50px;
      }
      .box ul li:nth-child(2n) {
        background: url(img/8.png);
        background-size: 100px 50px;
      }
      .box ul li:nth-child(3n) {
        background: url(img/25.png);
        background-size: 100px 50px;
      }
      .box ul li:nth-child(4n) {
        background: url(img/12.png);
        background-size: 100px 50px;
      }
      @keyframes move {
        to {
          transform: translateX(0px);
        }
      }
    </style>
  </head>
  <body>
    <div class="box">
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
      </ul>
    </div>
  </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值