asimryu

simple slide example 2(2015.06.16)

Jun 15th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <style>
  6.     #slider {
  7.         width: 300px;
  8.         height: 200px;
  9.         position: relative;
  10.         list-style: none;
  11.         margin: 0;
  12.         padding: 0;
  13.         overflow: hidden;
  14.     }
  15.     #slider > li {
  16.         width:300px;
  17.         height: 200px;
  18.         position: absolute;
  19.         left: 0;
  20.         top: 0;
  21.     }
  22. </style>
  23. <script src="http://code.jquery.com/jquery-latest.js"></script>
  24. </head>
  25. <body>
  26. <h1>Image Slide</h1>
  27. <ul id="slider">
  28.     <li><img src="http://lorempixel.com/300/200/nature"></li>
  29.     <li><img src="http://lorempixel.com/300/200/sports"></li>
  30.     <li><img src="http://lorempixel.com/300/200/cats"></li>
  31.     <li><img src="http://lorempixel.com/300/200/city"></li>
  32.     <li><img src="http://lorempixel.com/300/200/food"></li>
  33. </ul>
  34. <button id="start">시작</button>
  35. <button id="stop">중지</button>
  36. <script>
  37.     var timer = null;
  38.     var slides = $("#slider > li");
  39.     var first = 0;
  40.     var max = slides.length - 1;
  41.     $("#slider > li").hide();
  42.     $(slides[first]).show();
  43.     $(function(){
  44.  
  45.         $("#slider").click(function(){
  46.             first = first + 1; //first++
  47.             if( first > max ) first = 0;
  48.             $("#slider > li").hide();
  49.             $(slides[first]).show();
  50.         });
  51.  
  52.         $("#start").click(function(){
  53.             if( timer == null ) {
  54.                 timer = setInterval(function(){
  55.                     //
  56.                 },1000);
  57.             }
  58.         });
  59.  
  60.         $("#stop").click(function(){
  61.             if( timer != null ) {
  62.                 //
  63.             }
  64.         });
  65.  
  66.     });
  67.  
  68. </script>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment