asimryu

jquery slider top/down by lee

Jun 11th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.70 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <title>Document</title>
  5.     <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  6.     <style>
  7.         #slide { position:relative; width:900px; height:300px; overflow:hidden; }
  8.         #slide img{ position:absolute; top:0; left:0;}
  9.         .prevnext { position:absolute; top:135px; left:0; width:100%; height:30px;}
  10.         .prevnext div { width:50px; height:30px; background:#fff; line-height:30px;text-align:center; opacity:0.5; cursor:pointer;}
  11.         .prevnext div:hover {color:red;}
  12.         .prevnext .prev { float:left; margin-left:430px; margin-top:120px; }
  13.         .prevnext .next { float:right;margin-right:420px;margin-top:-260px; }
  14.     </style>
  15. </head>
  16. <body>
  17.     <div id="slide">
  18.         <img id="s1" src="http://lorempixel.com/900/300/city">
  19.         <img id="s2" src="http://lorempixel.com/900/300/food">
  20.         <img id="s3" src="http://lorempixel.com/900/300/nature">
  21.         <img id="s4" src="http://lorempixel.com/900/300/animals">
  22.         <img id="s5" src="http://lorempixel.com/900/300/business">
  23.         <div class="prevnext">
  24.             <div class="prev">bottom</div>
  25.             <div class="next">top</div>
  26.         </div>
  27.     </div>
  28.     <script>
  29.         $("#slide img").css("top","-300px");
  30.         $("#s1").css("top","0");
  31.         var sno = 1;
  32.         function fade(num) {
  33.                 if(num < 1) {
  34.                     $("#s" + sno).animate({top: "-300px"}, 500);
  35.                 } else {
  36.                     $("#s" + sno).animate({top: "300px"}, 500);
  37.                 }
  38.  
  39.                 sno += num;
  40.                 if(sno > 5) sno = 1;
  41.                 if(sno < 1) sno = 5;
  42.                 if(num < 1) {
  43.                     $("#s" + sno).css("top","300px");
  44.                 } else {
  45.                     $("#s" + sno).css("top","-300px");
  46.                 }
  47.                 $("#s" + sno).animate({top: "0"}, 500);
  48.         }
  49.         $(".prev").click( function(){fade(-1);} );
  50.         $(".next").click( function(){fade(1);} );
  51.     </script>
  52. </body>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment