Advertisement
asimryu

간단한슬라이드(20150908)

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