zoukankan      html  css  js  c++  java
  • css实现幻灯片播放效果

    用css实现幻灯片播放是最基础的,闲下来没事就试着写了一下,如果有不够完善或者方法不好的地方还请指点。下面我就用两种方法实现css花灯片效果。

    方法1:定位。通过position属性改变left值

    html代码:

    <section id=box>
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>1</li>
      </ul>
    </section>

    css代码:

    <style>
        * {
          margin: 0;
          padding: 0;
          font-family: 微软雅黑;
          list-style: none;
        }
        #box{
            400px;
            height:200px;
            border: 1px solid #000;
            margin: 50px auto;
            position:relative;
            overflow: hidden;
        }
        ul{
             2000px;
            position: absolute;
            top:0;
            left:0;
          animation: dh 10s infinite ease;
        }
        ul li{
          400px;
          height:200px;
          float: left;
    
        }
        ul li:nth-child(1){
          background:#4b86db;
        }
        ul li:nth-child(2){
          background:#ff9999;
        }
        ul li:nth-child(3){
          background:olivedrab;
        }
        ul li:nth-child(4){
          background:skyblue;
        }
        ul li:nth-child(5){
          background:#4b86db;
        }
            @keyframes dh {
              0%{
                left:0px;
          }
              25%{
                left:-400px;
              }
              50%{
                left:-800px;
              }
              75%{
                left:-1200px;
              }
              100%{
                left:-1600px;
              }
        }
    </style>

    方法2:2D转换。通过transfrom属性

    html代码:

    <section id=box>
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>1</li>
      </ul>
    </section>

    css代码:

    <style>
        * {
          margin: 0;
          padding: 0;
          font-family: 微软雅黑;
          list-style: none;
        }
        #box{
            400px;
            height:200px;
            border: 1px solid #000;
            margin: 50px auto;
            overflow: hidden;
        }
        ul{
           2000px;
          animation: dh 10s infinite ease;
        }
        ul li{
          400px;
          height:200px;
          float: left;
    
        }
        ul li:nth-child(1){
          background:#4b86db;
        }
        ul li:nth-child(2){
          background:#ff9999;
        }
        ul li:nth-child(3){
          background:olivedrab;
        }
        ul li:nth-child(4){
          background:skyblue;
        }
        ul li:nth-child(5){
          background:#4b86db;
        }
     
    @keyframes dh {
          0%{transform: translateX(0)}
          25%{transform: translateX(-400px)}
          50%{transform: translateX(-800px)}
          75%{transform: translateX(-1200px)}
          100%{transform: translateX(-1600px)}
    }
      </style>

    以上两种方法是我想到最简单的方法,如果有更好的方法还请朋友们留言指教。

  • 相关阅读:
    抽象类
    继承
    面向对象的静态属性,类方法,静态方法
    查找linux系统下的端口被占用进程的两种方法 【转】
    awk学习
    【转】借助LVS+Keepalived实现负载均衡
    ORA-28001: the password has expired解决方法
    ORACLE的还原表空间UNDO写满磁盘空间,解决该问题的具体步骤
    Oracle控制文件多路复用以及Oracle备份重建控制文件
    RedHat6.1通过配置yum server安装软件包
  • 原文地址:https://www.cnblogs.com/sdcs/p/8283824.html
Copyright © 2011-2022 走看看