asimryu

jquery slide 20141030-1

Oct 29th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.94 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="ko">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>slide</title>
  6. <style>
  7.     body{margin:0;}
  8.     #slidebox{position:relative;width:500px;height:300px;   margin:10px auto;overflow:hidden;}
  9.     #slide{width:500px;height:300px;overflow:hidden;list-style:none;    padding:0;margin:0;}
  10.     #slide li{position:absolute;left:0;top:0;}
  11.     #buttons{width:500px;height:auto;text-align:center; margin:0 auto;}
  12. </style>
  13. </head>
  14. <body>
  15.     <div id="slidebox">
  16.         <ul id="slide">
  17.             <li><img src="http://lorempixel.com/500/300/food"></li>
  18.             <li><img src="http://lorempixel.com/500/300/nature"></li>
  19.             <li><img src="http://lorempixel.com/500/300/animals"></li>
  20.             <li><img src="http://lorempixel.com/500/300/city"></li>
  21.         </ul>
  22.     </div>
  23.     <div id="buttons">
  24.         <button id="prev">이전</button>
  25.         <button id="next">다음</button>
  26.         <button id="up">위로</button>
  27.         <button id="down">아래로</button>
  28.         <button id="start">시작</button>
  29.         <button id="stop">중지</button>
  30.     </div>
  31.     <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  32.     <script type="text/javascript">
  33.  
  34.         $(function(){
  35.  
  36.             $("#slide > li").css("left",-500);
  37.             var slides = $("#slide > li");
  38.             var sno = 0;
  39.             var max = slides.length - 1;
  40.             $(slides[sno]).css({left:0,top:0});
  41.             var isanimate = false;
  42.             var direction = "next";
  43.        
  44.             $("#next").click(function(){
  45.                 if( isanimate ) return;
  46.                 direction = "next";
  47.                 isanimate = true;
  48.                 $(slides[sno]).animate({left:500},1000,function(){isanimate=false;});
  49.                 sno++;
  50.                 if(sno>max) sno=0;
  51.                 $("#slide > li").css({left:-500,top:0});
  52.                 $(slides[sno]).animate({left:0},1000);
  53.             });
  54.  
  55.             $("#prev").click(function(){
  56.                 if( isanimate ) return;
  57.                 direction = "prev";
  58.                 isanimate = true;
  59.                 $(slides[sno]).animate({left:-500},1000,function(){isanimate=false;});
  60.                 sno--;
  61.                 if(sno<0) sno=max;
  62.                 $("#slide > li").css({left:500,top:0});
  63.                 $(slides[sno]).animate({left:0},1000);
  64.             });
  65.  
  66.             $("#up").click(function(){
  67.                 if( isanimate ) return;
  68.                 direction = "up";
  69.                 isanimate = true;
  70.                 $(slides[sno]).animate({top:-300},1000,function(){isanimate=false;});
  71.                 sno++;
  72.                 if(sno>max) sno=0;
  73.                 $("#slide > li").css({left:0,top:300});
  74.                 $(slides[sno]).animate({top:0},1000);
  75.             });
  76.  
  77.             $("#down").click(function(){
  78.                 if( isanimate ) return;
  79.                 direction = "down";
  80.                 isanimate = true;
  81.                 $(slides[sno]).animate({top:300},1000,function(){isanimate=false;});
  82.                 sno--;
  83.                 if(sno<0) sno=max;
  84.                 $("#slide > li").css({left:0,top:-300});
  85.                 $(slides[sno]).animate({top:0},1000);
  86.             });
  87.  
  88.             var timer = null;
  89.             $("#start").click(function(){
  90.                 if( timer == null ) {
  91.                     timer = setInterval(function(){ $("#" + direction).click(); },3000);
  92.                 }
  93.             });
  94.  
  95.             $("#stop").click(function(){
  96.                 if( timer != null ) {
  97.                     clearInterval(timer);
  98.                     timer = null;
  99.                 }
  100.             });
  101.  
  102.             $("#start").click();
  103.  
  104.         });
  105.  
  106.     </script>
  107. </body>
  108. </html>
Advertisement
Add Comment
Please, Sign In to add comment