asimryu

fade in/out

Jun 11th, 2014
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.42 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;}
  13.         .prevnext .next { float:right;}
  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">Prev</div>
  25.             <div class="next">Next</div>
  26.         </div>
  27.     </div>
  28.     <script>
  29.         $("#slide img").hide();
  30.         $("#s1").show();
  31.         var sno = 1;
  32.         function fade(num) {
  33.                 $("#s" + sno).fadeOut();
  34.                 sno = sno + num;
  35.                 if(sno > 5) sno = 1;
  36.                 if(sno < 1) sno = 5;
  37.                 $("#s" + sno).fadeIn();
  38.         }
  39.         $(".prev").click( function(){fade(1);} );
  40.         $(".next").click( function(){fade(-1);} );
  41.         var timer = setInterval(function(){fade(1);},2000);
  42.     </script>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment