Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <title>Document</title>
- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
- <style>
- #slide { position:relative; width:900px; height:300px; overflow:hidden; }
- #slide img{ position:absolute; top:0; left:0;}
- .prevnext { position:absolute; top:135px; left:0; width:100%; height:30px;}
- .prevnext div { width:50px; height:30px; background:#fff; line-height:30px;text-align:center; opacity:0.5; cursor:pointer;}
- .prevnext div:hover {color:red;}
- .prevnext .prev { float:left;}
- .prevnext .next { float:right;}
- </style>
- </head>
- <body>
- <div id="slide">
- <img id="s1" src="http://lorempixel.com/900/300/city">
- <img id="s2" src="http://lorempixel.com/900/300/food">
- <img id="s3" src="http://lorempixel.com/900/300/nature">
- <img id="s4" src="http://lorempixel.com/900/300/animals">
- <img id="s5" src="http://lorempixel.com/900/300/business">
- <div class="prevnext">
- <div class="prev">Prev</div>
- <div class="next">Next</div>
- </div>
- </div>
- <script>
- $("#slide img").css("left","-900px");
- $("#s1").css("left","0");
- var sno = 1;
- function fade(num) {
- if(num < 1) {
- $("#s" + sno).animate({left: "-900px"}, 500);
- } else {
- $("#s" + sno).animate({left: "900px"}, 500);
- }
- sno = sno + num;
- if(sno > 5) sno = 1;
- if(sno < 1) sno = 5;
- if(num < 1) {
- $("#s" + sno).css("left","900px");
- } else {
- $("#s" + sno).css("left","-900px");
- }
- $("#s" + sno).animate({left: "0"}, 500);
- }
- $(".prev").click( function(){fade(-1);} );
- $(".next").click( function(){fade(1);} );
- //아래 줄의 주석을 제거하면 자동으로 매 2초마다 슬라이드 재생됨.
- //var timer = setInterval(function(){fade(1);},2000);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment