使用纯css3实现图片轮播

  1.  
  2. <!DOCTYPE html>  
  3. <html>  
  4.  <head>  
  5.   <title> 飛天网事--纯CSS代码实现图片轮播 </title>  
  6.   <meta charset="utf-8" />  
  7.   <meta name="description" content="飛天网事,WEB前端开发,纯css3代码图片轮播,HTML5+CSS3精彩案例" />  
  8.   <meta name="keywords" content="飛天网事,WEB前端开发,HTML5,CSS3,jQuery," />  
  9.     <meta name="author" content="R.tian @eduppp.cn 2015">  
  10.     <link rel="shortcut icon"  href="http://eduppp.cn/images/logo4.gif" />  
  11.     <link rel="apple-touch-icon" href="http://eduppp.cn/images/logo.gif" />  
  12.   <style type="text/css">  
  13.         #frame {/*----------图片轮播相框容器----------*/  
  14.             position: absolute; /*--绝对定位,方便子元素的定位*/  
  15.             width: 300px;  
  16.             height: 200px;  
  17.             overflow: hidden;/*--相框作用,只显示一个图片---*/  
  18.             border-radius:5px;  
  19.         }  
  20.         #dis {/*--绝对定位方便li图片简介的自动分布定位---*/  
  21.             position: absolute;  
  22.             left: -50px;  
  23.             top: -10px;  
  24.             opacity: 0.5;  
  25.         }  
  26.         #dis li {  
  27.             display: inline-block;  
  28.             width: 200px;  
  29.             height: 20px;  
  30.             margin: 0 50px;  
  31.             float: left;  
  32.             text-align: center;  
  33.             color: #fff;  
  34.             border-radius: 10px;  
  35.             background: #000;  
  36.         }  
  37.         #photos img {  
  38.             float: left;  
  39.             width:300px;  
  40.             height:200px;  
  41.         }  
  42.         #photos {/*---设置总的图片宽度--通过位移来达到轮播效果----*/  
  43.             position: absolute;z-index:9px;  
  44.             width: calc(300px * 5);/*---修改图片数量的话需要修改下面的动画参数*/  
  45.         }  
  46.         .play{  
  47.             animation: ma 20s ease-out infinite alternate;/**/  
  48.         }  
  49.         @keyframes ma {/*---每图片切换有两个阶段:位移切换和静置。中间的效果可以任意定制----*/  
  50.             0%,20% {        margin-left: 0px;       }  
  51.             25%,40% {       margin-left: -300px;    }  
  52.             45%,60% {       margin-left: -600px;    }  
  53.             65%,80% {       margin-left: -900px;    }  
  54.             85%,100% {      margin-left: -1200px;   }  
  55.         }  
  56.         .num{  
  57.             position:absolute;z-index:10;  
  58.             display:inline-block;  
  59.             right:10px;top:165px;  
  60.             border-radius:100%;  
  61.             background:#f00;  
  62.             width:25px;height:25px;  
  63.             line-height:25px;  
  64.             cursor:pointer;  
  65.             color:#fff;  
  66.             text-align:center;  
  67.             opacity:0.8;  
  68.         }  
  69.         .num:hover{background:#00f;}  
  70.         .num:hover,#photos:hover{animation-play-state:paused;}  
  71.         .num:nth-child(2){margin-right:30px}  
  72.         .num:nth-child(3){margin-right:60px}  
  73.         .num:nth-child(4){margin-right:90px}  
  74.         .num:nth-child(5){margin-right:120px}  
  75.         #a1:hover ~ #photos{animation: ma1 .5s ease-out forwards;}  
  76.         #a2:hover ~ #photos{animation: ma2 .5s ease-out forwards;}  
  77.         #a3:hover ~ #photos{animation: ma3 .5s ease-out forwards;}  
  78.         #a4:hover ~ #photos{animation: ma4 .5s ease-out forwards;}  
  79.         #a5:hover ~ #photos {animation: ma5 .5s ease-out forwards;}  
  80.         @keyframes ma1 {0%{margin-left:-1200px;}100%{margin-left:-0px;} }  
  81.         @keyframes ma2 {0%{margin-left:-1200px;}100%{margin-left:-300px;}   }  
  82.         @keyframes ma3 {100%{margin-left:-600px;}   }  
  83.         @keyframes ma4 {100%{margin-left:-900px;}   }  
  84.         @keyframes ma5 {100%{margin-left:-1200px;}  }  
  85.   </style>  
  86.  </head>  
  87.  <body>  
  88.  <div id="frame" >  
  89.         <id="a1" class="num">1</a>  
  90.         <id="a2" class="num">2</a>  
  91.         <id="a3" class="num">3</a>  
  92.         <id="a4" class="num">4</a>  
  93.         <id="a5" class="num">5</a>  
  94.         <div id="photos" class="play">  
  95.               <img src="http://eduppp.cn/images/0/1.jpg" >  
  96.               <img src="http://eduppp.cn/images/0/3.jpg" >  
  97.               <img src="http://eduppp.cn/images/0/4.jpg" >  
  98.               <img src="http://eduppp.cn/images/0/5.jpg" >  
  99.               <img src="http://eduppp.cn/images/0/2.jpg" >  
  100.               <ul id="dis">  
  101.                 <li>中国标志性建筑:天安门</li>  
  102.                 <li>中国标志性建筑:东方明珠</li>  
  103.                 <li>中国标志性建筑:布达拉宫</li>  
  104.                 <li>中国标志性建筑:长城</li>  
  105.                 <li>中国标志性建筑:天坛</li>  
  106.               </ul>  
  107.         </div>  
  108. </div>  
  109. </body>  
  110. </html>  

《借鉴地址:http://blog.csdn.net/rtian001/article/details/48474677》

posted @ 2016-10-16 13:45  祥福有梦想  阅读(1956)  评论(0编辑  收藏  举报