Advertisement
asimryu

jqury slide 기초 1

Sep 8th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.45 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>슬라이드</title>
  6. <script src="js/jquery-1.11.3.js"></script>
  7. <style>
  8.     #slider {
  9.         width: 500px;
  10.         height: 300px;
  11.         border: 1px solid #000;
  12.         overflow: hidden;
  13.     }
  14.     #slider img {
  15.         display: none;
  16.     }
  17. </style>
  18. </head>
  19. <body>
  20.     <div id="slider" onclick="slide(1);">
  21.         <img id="p1" src="images/food.jpg" width="500" height="300" alt="food">
  22.         <img id="p2" src="images/sports.jpg" width="500" height="300" alt="sports">
  23.         <img id="p3" src="images/nature.jpg" width="500" height="300" alt="nature">
  24.         <img id="p4" src="images/fashion.jpg" width="500" height="300" alt="fashion">
  25.         <img id="p5" src="images/transport.jpg" width="500" height="300" alt="transport">
  26.     </div>
  27.     <button onclick="slide(-1);">이전</button>
  28.     <span id="cno">1</span>
  29.     <button onclick="slide(1);">다음</button>
  30.     <button onclick="auto();">자동슬라이드 시작/중지</button>
  31.     <script>
  32.         $("#p1").show();
  33.         var sno = 1;
  34.         var max = 5;
  35.         function slide(n){
  36.             sno = sno + n; // = sno++
  37.             if( sno > max ) sno = 1;
  38.             if( sno < 1 ) sno = max;
  39.             $("#cno").html(sno);
  40.             for( var i=1; i<=max; i++){
  41.                 if( i == sno ) $("#p" + i).show(); else $("#p" + i).hide();
  42.             }
  43.         }
  44.         var timer = null;
  45.         function auto(){
  46.             if( timer == null ) {
  47.                 timer = setInterval( function(){ slide(1); }, 1000 );
  48.             } else {
  49.                 clearInterval(timer);
  50.                 timer = null;
  51.             }
  52.         }
  53.     </script>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement