Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>slide</title>
- <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
- <style>
- /* 태그 */
- body { margin:0; background:#333; }
- button { padding:3px 10px; background:#bebebe; border:none; background:#33a0ff; color:#fff; font-weight:bold; font-family:"Malgun Gothic"; cursor:pointer; }
- button:hover { opacity:.7; }
- /* 아이디 */
- #slidebox { position:relative; width:500px; height:300px; margin:0 auto; overflow:hidden; margin-top:50px; }
- #slide { width:500px; height:300px; list-style:none; padding:0; margin:0; }
- #slide li { position:absolute; left:0; top:0; }
- #numbers { margin-bottom:10px; }
- /* 클래스 */
- .title { width:100%; position:absolute; bottom:0; padding:20px 0; background:rgba(0,0,0,0.5); font-family:"Malgun Gothic"; color:#fff; font-weight:bold; text-align:center; font-size:18px; }
- .center { position:relative; margin:20px auto; width:210px; }
- .mt20 { margin-top:20px; }
- .p { background:#bebebe; width:10px; height:10px; border-radius:50%; float:left; margin-right:20px; cursor:pointer; position:relative; z-index:10; }
- .p:last-child { margin-right:0; }
- .wh { width:100%; float:left; margin-bottom:20px; }
- .on { background:#33a0ff; cursor:pointer; }
- </style>
- </head>
- <body>
- <!-- 코드 by 최우연 -->
- <!-- 슬라이드 -->
- <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/sports"></li>
- <li title="도시"><img src="http://lorempixel.com/500/300/city"></li>
- <li title="사람"><img src="http://lorempixel.com/500/300/people"></li>
- <li title="비즈니스"><img src="http://lorempixel.com/500/300/business"></li>
- <li title="패션"><img src="http://lorempixel.com/500/300/fashion"></li>
- </ul>
- </div>
- <!-- 위치버튼 -->
- <div id="numbers" class="center">
- <div class="wh"></div>
- </div>
- <!-- 버튼 -->
- <div class="center mt20">
- <button id="prev" onClick="animation('prev')">이전</button>
- <button id="next" onClick="animation('next');">다음</button>
- <button id="up" onClick="animation('up');"> 위 </button>
- <button id="down" onClick="animation('down');">아래</button>
- </div>
- <script>
- $(function(){
- /* 변수설정 */
- slides = $("#slide > li");
- num = 0;
- max = slides.length-1;
- chk = true;
- p = "";
- /* 기본위치 셋팅 */
- slides.css("left",-500);
- $(slides[num]).css("left",0);
- /* 타이틀 추가 */
- $("#slide li").each(function() {
- var title = $(this).attr("title");
- var title_html = "<div class='title'>"+title+"</div>";
- $(this).append(title_html);
- });
- /* 위치버튼 추가 */
- for(i=1;i<=max+1;i++){
- p += "<div class='p' data-idx='"+(i-1)+"'></div>";
- }
- $("#numbers .wh").append(p);
- $("#numbers .p:first-child").addClass("on");
- $(".p").click(function(){
- animation($(this).attr("data-idx"));
- });
- /* 자동슬라이드 */
- setInterval(function(){
- animation('next');
- },5000);
- });
- function animation(a){
- /* access */
- if(!chk) return;
- if(!isNaN(a) && a==num)return;
- /* 변수설정 */
- chk=false;
- var move;
- var move2;
- /* 이동방향 설정 */
- switch(a){
- case 'prev':
- move=500;
- move2=-500;
- break;
- case 'up' :
- move=-300;
- move2=300;
- break;
- case 'down' :
- move=300;
- move2=-300;
- break;
- default:
- move=-500;
- move2=500;
- break;
- }
- /* 현재이미지 이동 */
- if(a=='next'||a=='prev' || !isNaN(a)){
- $(slides[num]).animate({left:move},500,function(){chk=true;});
- } else {
- $(slides[num]).animate({top:move},500,function(){chk=true;});
- }
- /* 이동방향 */
- if(a=='prev' || a=='down'){
- if(--num<0) num=max;
- } else {
- if(++num>max)num=0;
- }
- /* 위치버튼 클릭시 변수값변경 */
- if(!isNaN(a)){
- num=Number(a);
- }
- /* 위치버튼 css설정 */
- $(".p").removeClass("on");
- $(".p[data-idx="+num+"]").addClass("on");
- /* 보여줄 이미지 이동 */
- if(a=='next'||a=='prev' || !isNaN(a)){
- $(slides[num]).css({left:move2,top:0}).animate({left:0},500);
- } else {
- $(slides[num]).css({top:move2,left:0}).animate({top:0},500);
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment