純css實現輪播圖

來源:互聯網
上載者:User

標籤:main   demo   anim   gif   flow   hot   com   osi   tle   

輪播圖的實現原理其實是比較簡單的

舉個例子    

<div  class="main"><div class="div-main"></div></div>

main的寬度是100px

div-main的寬度是500px

我們用js控制div-main往左或往右移動,這樣就實現了輪播,簡單把

好了,先介紹個 css3的api 

animation: myfirst 5s linear 2s infinite alternate;

myfirst:動畫名

5s:動畫多久執行完

linear:動畫以什麼曲線執行

2s:動畫延遲多長時間執行

infinite:該參數是動畫一直迴圈,可以寫數字也行

alternate:只動畫在倒過來執行

先介紹到這裡,完整用法可以參考:css3動畫api參考

下面上代碼:

 

<!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>RunJS</title>    </head>    <body>        <div id="frame" >    <div id="photos" class="play">        <div class="img"></div>        <div class="img"></div>        <div class="img"></div>        <div class="img"></div>        <ul id="dis">            <li>111111111111111</li>            <li>22222222222222</li>            <li>33333333333333</li>            <li>44444444444444</li>        </ul>    </div></div>    </body></html>
   #frame{position:absolute;width:302px;height:200px;overflow:hidden;border-radius:5px}    #dis{position:absolute;left:-50px;top:-10px;opacity:.5}    #dis li{display:inline-block;width:200px;height:20px;margin:0 50px;float:left;text-align:center;color:#fff;border-radius:10px;background:#000}    #photos .img{float:left;width:300px;height:200px;background-color:red;border-left:1px solid blue;}    #photos {  position: absolute;z-index:9;  width: calc(301px * 4);/*---修改圖片數量的話需要修改下面的動畫參數*/  }    .play{ animation: ma 5s ease-out infinite alternate;}    @keyframes ma {        0%,25% {        margin-left: 0px;       }        30%,50% {       margin-left: -300px;    }        55%,75% {       margin-left: -600px;    }        80%,100% {       margin-left: -900px;    }    }

 

 正所謂什麼代碼也比不上一個   線上運行demo

純css實現輪播圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.