Advertisement
asimryu

아주 간단한 슬라이드 (2015.08.27)

Aug 26th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.00 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Slider #1</title>
  6. <style> #slider img { display:none; } </style>
  7. </head>
  8. <body>
  9.     <div id="slider">
  10.         <img id="p1" src="http://lorempixel.com/500/300/nature">
  11.         <img id="p2" src="http://lorempixel.com/500/300/sports">
  12.         <img id="p3" src="http://lorempixel.com/500/300/animals">
  13.         <img id="p4" src="http://lorempixel.com/500/300/food">
  14.     </div>
  15.     <div>
  16.         <button onclick="next(-1)">이전</button>
  17.         <button onclick="next(1)">다음</button>
  18.     </div>
  19.     <script>
  20.         var pno = 0;
  21.         function next(n){
  22.             if( n === 1) {
  23.                 pno = pno + 1;
  24.                 if( pno > 4 ) pno = 1;
  25.             } else if( n === -1 ) {
  26.                 pno = pno - 1;
  27.                 if( pno < 1 ) pno = 4;
  28.             } else {
  29.                 return;
  30.             }
  31.             for( var i=1; i<=4; i++){
  32.                 var pid = "p" + i;
  33.                 var photo = document.getElementById(pid);
  34.                 if( pno == i ) {
  35.                     photo.style.display = "block";
  36.                 } else {
  37.                     photo.style.display = "none";
  38.                 }
  39.             }
  40.         }
  41.         next(1);
  42.     </script>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement