Use pure CSS3 to achieve picture carousel

Source: Internet
Author: User

  1. <! DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title> Fly skynet-pure CSS Code implementation picture Carousel </title>
  5. <meta charset="utf-8" />
  6. <meta name="description" content= "fly skynet, Web front-end development, pure CSS3 code picture carousel, html5+css3 wonderful case" />
  7. <meta name="keywords" content="fly skynet, Web front-end development, html5,css3,jquery," />
  8. <meta name= "author" content="r.tian @eduppp. cn">
  9. <link rel="shortcut icon" href="http://eduppp.cn/images/logo4.gif" /> /c12>
  10. <link rel= "apple-touch-icon" href="http://eduppp.cn/images/logo.gif" />
  11. <style type="text/css">
  12. #frame {/*----------picture Carousel Frame container----------*/
  13. position:absolute; /*--absolute positioning, Convenient sub-element positioning */
  14. width:300px;
  15. height:200px;
  16. Overflow:hidden;/*--photo frame, Show Only one picture---*/
  17. border-radius:5px;
  18. }
  19. #dis {/*--absolute Positioning Convenient Li picture introduction of the automatic distribution positioning---*/
  20. position:absolute;
  21. Left: -50px;
  22. Top: -10px;
  23. opacity:0.5;
  24. }
  25. #dis Li {
  26. display:inline-block;
  27. width:200px;
  28. height:20px;
  29. margin:0 50px;
  30. float:left;
  31. text-align:center;
  32. Color: #fff;
  33. border-radius:10px;
  34. Background: #000;
  35. }
  36. #photos img {
  37. float:left;
  38. width:300px;
  39. height:200px;
  40. }
  41. #photos {/*---sets The overall picture width--by displacement to achieve the carousel effect----*/
  42. position:absolute;z-index:9px;
  43. Width:calc (300px * 5);/*---modify The number of pictures, you need to modify the following animation parameters */
  44. }
  45. . play{
  46. Animation:ma 20s Ease-out Infinite alternate;/**/
  47. }
  48. @keyframes Ma {/*---there are two stages for each picture switch: displacement toggle and Static. The intermediate effect can be arbitrarily customized----*/
  49. 0%,20% {margin-left:0px; }
  50. 25%,40% {margin-left: -300px; }
  51. 45%,60% {margin-left: -600px; }
  52. 65%,80% {margin-left: -900px; }
  53. 85%,100% {margin-left: -1200px; }
  54. }
  55. . num{
  56. position:absolute;z-index:10;
  57. display:inline-block;
  58. right:10px;top:165px;
  59. border-radius:100%;
  60. Background: #f00;
  61. width:25px;height:25px;
  62. line-height:25px;
  63. cursor:pointer;
  64. Color: #fff;
  65. text-align:center;
  66. opacity:0.8;
  67. }
  68. . num:hover{background: #00f;}
  69. . num:hover, #photos: hover{animation-play-state:paused;}
  70. . Num:nth-child (2) {margin-right:30px}
  71. . Num:nth-child (3) {margin-right:60px}
  72. . Num:nth-child (4) {margin-right:90px}
  73. . Num:nth-child (5) {margin-right:120px}
  74. #a1: Hover ~ #photos {animation:ma1.5s ease-out forwards;}
  75. #a2: Hover ~ #photos {animation:ma2.5s ease-out forwards;}
  76. #a3: Hover ~ #photos {animation:ma3.5s ease-out forwards;}
  77. #a4: Hover ~ #photos {animation:ma4.5s ease-out forwards;}
  78. #a5: Hover ~ #photos {animation:ma5.5s ease-out forwards;}
  79. @keyframes MA1 {0%{margin-left:-1200px;} 100%{margin-left:-0px;}}
  80. @keyframes Ma2 {0%{margin-left:-1200px;}   100%{margin-left:-300px;} }
  81. @keyframes MA3 {100%{margin-left:-600px;} }
  82. @keyframes MA4 {100%{margin-left:-900px;} }
  83. @keyframes MA5 {100%{margin-left:-1200px;} }
  84. </style>
  85. </head>
  86. <body>
  87. <div id="frame" >
  88. <a id="a1" class="num">1</a>
  89. <a id="a2" class="num">2</a>
  90. <a id="a3" class="num">3</a>
  91. <a id="a4" class="num">4</a>
  92. <a id="a5" class="num">5</a>
  93. <div id="photos" class="play">
  94. <img src="http://eduppp.cn/images/0/1.jpg" >
  95. <img src="http://eduppp.cn/images/0/3.jpg" >
  96. <img src="http://eduppp.cn/images/0/4.jpg" >
  97. <img src="http://eduppp.cn/images/0/5.jpg" >
  98. <img src="http://eduppp.cn/images/0/2.jpg" >
  99. <ul id="dis">
  100. <li> China iconic building: Tiananmen </li>
  101. <li> China iconic building: Oriental Pearl </li>
  102. <Li> Chinese iconic architecture: Potala Palace </li>
  103. <li> China iconic building: Great Wall </li>
  104. <Li> Chinese iconic building: Temple of Heaven </li>
  105. </ul>
  106. </div>
  107. </div>
  108. </body>
  109. </html>

"reference address: http://blog.csdn.net/rtian001/article/details/48474677"

Use pure CSS3 to achieve picture carousel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.