Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="ko">
- <head>
- <meta charset="UTF-8">
- <title>slide</title>
- <style>
- body{margin:0;}
- #slidebox{position:relative;width:500px;height:300px; margin:10px auto;overflow:hidden;}
- #slide{width:500px;height:300px;overflow:hidden;list-style:none; padding:0;margin:0;}
- #slide li{position:absolute;left:0;top:0;}
- #buttons, #numbers, #imgtitle{width:500px;height:auto;text-align:center; margin:0 auto;}
- </style>
- </head>
- <body>
- <div id="slidebox">
- <ul id="slide">
- <li title="음식 이미지입니다."><img src="http://lorempixel.com/500/300/food"></li>
- <li title="멋진 자연입니다."><img src="http://lorempixel.com/500/300/nature"></li>
- <li title="동물을 사랑합시다."><img src="http://lorempixel.com/500/300/animals"></li>
- <li title="우리의 도시는 아름답습니다."><img src="http://lorempixel.com/500/300/city"></li>
- <li title="열심히 운동합시다."><img src="http://lorempixel.com/500/300/sports"></li>
- </ul>
- </div>
- <div id="imgtitle"></div>
- <div id="numbers"></div>
- <div id="buttons">
- <button id="prev">이전</button>
- <button id="next">다음</button>
- <button id="up">위로</button>
- <button id="down">아래로</button>
- <button id="start">시작</button>
- <button id="stop">중지</button>
- </div>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
- <script type="text/javascript">
- $(function(){
- $("#slide > li").css("left",-500);
- var slides = $("#slide > li");
- var sno = 0;
- var max = slides.length - 1;
- $(slides[sno]).css({left:0,top:0});
- var isanimate = false;
- var direction = "next";
- for( var i = 0; i <= max; i++ ) {
- var addhtml = " <a href='" + i + "'>" + (i+1) + "</a> ";
- $("#numbers").append( addhtml );
- }
- changeNumberColor();
- $("#numbers a").click(function(event){
- event.preventDefault();
- var tmpNo = $(this).attr("href");
- if(direction == "next" || direction == "dow"){
- sno = parseInt(tmpNo) - 1;
- if(sno < 0) sno = max;
- } else if(direction == "prev" || direction == "up"){
- sno = parseInt(tmpNo) + 1;
- if(sno >max) sno = 0;
- }
- isanimate = false;
- if( timer == null ) {
- $("#" + direction).click();
- }else{
- $("#stop").click();
- $("#" + direction).click();
- $("#start").click();
- }
- });
- $("#next").click(function(){
- if( isanimate ) return;
- direction = "next";
- isanimate = true;
- $(slides[sno]).animate({left:500},1000,function(){isanimate=false;});
- sno++;
- if(sno>max) sno=0;
- $("#slide > li").css({left:-500,top:0});
- $(slides[sno]).animate({left:0},1000);
- changeNumberColor();
- });
- $("#prev").click(function(){
- if( isanimate ) return;
- direction = "prev";
- isanimate = true;
- $(slides[sno]).animate({left:-500},1000,function(){isanimate=false;});
- sno--;
- if(sno<0) sno=max;
- $("#slide > li").css({left:500,top:0});
- $(slides[sno]).animate({left:0},1000);
- changeNumberColor();
- });
- $("#up").click(function(){
- if( isanimate ) return;
- direction = "up";
- isanimate = true;
- $(slides[sno]).animate({top:-300},1000,function(){isanimate=false;});
- sno++;
- if(sno>max) sno=0;
- $("#slide > li").css({left:0,top:300});
- $(slides[sno]).animate({top:0},1000);
- changeNumberColor();
- });
- $("#down").click(function(){
- if( isanimate ) return;
- direction = "down";
- isanimate = true;
- $(slides[sno]).animate({top:300},1000,function(){isanimate=false;});
- sno--;
- if(sno<0) sno=max;
- $("#slide > li").css({left:0,top:-300});
- $(slides[sno]).animate({top:0},1000);
- changeNumberColor();
- });
- function changeNumberColor(){
- var slidelinks = $("#numbers a");
- for(var i = 0; i < slidelinks.length; i++){
- if(i == sno) {
- $(slidelinks[i]).css({color:"red",fontWeight:"bold"});
- var imgtitle = $(slides[sno]).attr("title");
- $("#imgtitle").html(imgtitle);
- } else {
- $(slidelinks[i]).css({color:"black",fontWeight:"normal"});
- }
- }
- }
- var timer = null;
- $("#start").click(function(){
- if( timer == null ) {
- timer = setInterval(function(){ $("#" + direction).click(); },3000);
- }
- });
- $("#stop").click(function(){
- if( timer != null ) {
- clearInterval(timer);
- timer = null;
- }
- });
- $("#start").click();
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment