純CSS3代碼實現簡單的圖片輪播

來源:互聯網
上載者:User

標籤:

以4張圖片為例:
1.基本布局:
將4張圖片左浮動橫向並排放入一個div容器內,圖片設定統一尺寸,div寬度設定4個圖片的總尺寸,然後放入相框容器div,
相框設定1個圖片的大小並設定溢出隱藏,以保證正確顯示一個照片。
2.設定動畫:
然後使用css3動畫,通過對photos進行位移,從而達到顯示不同的圖片,每次位移一個圖片的寬度,即可顯示下一張圖片。
4張圖片,需要切換3次.
根據需要可以對各個圖片添加相應的序號和圖片簡介。

3.代碼如下:
<style>
#frame{position:absolute;width:300px;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}
#photos { position: absolute;z-index:9; width: calc(300px * 4);/*---修改圖片數量的話需要修改下面的動畫參數*/ }
.play{ animation: ma 20s 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; }

}
</style>
<body>
<div id="frame" >
<div id="photos" class="play">
<img src="images/1.jpg" >
<img src="images/3.jpg" >
<img src="images/4.jpg" >
<img src="images/5.jpg" >
<ul id="dis">
<li>111111111111111</li>
<li>22222222222222</li>
<li>33333333333333</li>
<li>44444444444444</li>
</ul>
</div>
</div>

純CSS3代碼實現簡單的圖片輪播

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.