Advertisement
Guest User

Simple Slideshow

a guest
Sep 14th, 2014
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.18 KB | None | 0 0
  1. <style>
  2. /* the slide container with a fixed size */
  3. .slides {
  4.   box-shadow: 0px 0px 6px black;
  5.   margin: 0 auto;
  6.   width: 500px;
  7.   height: 300px;
  8.   position: relative;
  9. }
  10.  
  11. /* the images are positioned absolutely to stack. opacity transitions are animated. */
  12. .slides img {
  13.   display: block;
  14.   position: absolute;
  15.   transition: opacity 1s;
  16.   opacity: 0;
  17.   width: 100%;
  18. }
  19.  
  20. /* the first image is the current slide. it's faded in. */
  21. .slides img:first-child {
  22.   z-index: 2; /* frontmost */
  23.   opacity: 1;
  24. }
  25.  
  26. /* the last image is the previous slide. it's behind the current slide and it's faded over. */
  27. .slides img:last-child {
  28.   z-index: 1; /* behind current slide */
  29.   opacity: 1;
  30. }
  31. </style>
  32.  
  33. <div class="slides">
  34.   <img src="http://lorempixel.com/500/300/?r=1">
  35.   <img src="http://lorempixel.com/500/300/?r=2">
  36.   <img src="http://lorempixel.com/500/300/?r=3">
  37.   <img src="http://lorempixel.com/500/300/?r=4">
  38.   <img src="http://lorempixel.com/500/300/?r=5">
  39. </div>
  40.  
  41. <script>
  42. function nextSlide() {
  43.     var q = function(sel) { return document.querySelector(sel); }  
  44.     q(".slides").appendChild(q(".slides img:first-child"));
  45. }
  46. setInterval(nextSlide, 3000)
  47. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement