묻고답하기

본문소스를 올립니다.

슬라이더3에서 1로 돌아갈때 pre/next 함수를 만들어 자연스럽게 보이게 하고 싶은데 잘 안되네요

고수님들 도움주시면 감사하겠습니다.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
* {margin:0;padding:0;}
#wrap {
  width:100%;
  height:600px;
  position: relative;
}
  .wrap_abs_slider {
    width:100%;
    position: absolute;
    left:0;
    top:100px;
    height:500px;
    z-index: 0;

  }
  .wrap_sl_rel {
    width:100%;
    height:100%;
    position: relative;
    overflow: hidden;
  }
  .wrap_sl_rel>img {
    position: absolute;
    top:0;
    width:100%;
    height:500px;
  }
    .sl_img01 {
      left:0%;
      z-index: 3;
    }
    .sl_img02 {
      left:100%;
      z-index: 2;
    }
    .sl_img03 {
      left:200%;
      z-index: 1;
    }
.wrap_abs_con {
  position:absolute;
  width:1000px;
  left:50%;
  margin-left:-500px;
  top:100px;
  z-index: 1;
  height:500px;
}

.wrap_con_rel {
  position: relative;
  width:100%;
  height:100%;

}
.wrap_con_rel>button {
  position: absolute;
  top:50%;
  margin-top:-15px;
  height:30px;
  width:100px;
  border:0;
  background-color:#ff0000;
  color:#fff;
}
.left {
  left:0;

}
.right{
  right:0;
}
.s_btn {
  position: absolute;
  left:50%;
  margin-left: -75px;
  width:150px;
  height:30px;
  list-style-type: none;
  bottom:10px;
  overflow: hidden;
}
.s_btn>li {
  float: left;
}
.s_btn>li>a {
  display: block;
  width:30px;
  height:30px;
  margin-right:20px;
  background-color: gray;
  border-radius:15px;
}
.s_btn>li:nth-child(3)>a {
  margin-right: 0;
}
.s_btn>li>a:hover {

  background-color: #f00;
}

</style>
  </head>
  <body>
    <script type="text/javascript">
    $(function(){

      var w01 = 0;
      var w02 = 0;
      var w03 = 0;


      sl01 ();
      setInterval(right_Click,3000);

        $('.right').click(function(){

          if(w01 == 1){
             sl02();
          }
          else if(w02 == 1) {
            sl03();
          }
          else if(w03 == 1){
            sl_Next();
          }
        });


        $('.left').click(function(){

          if(w01 == 1){
             sl_Pre();
          }
          else if(w02 == 1) {
            sl01();
          }
          else if(w03 == 1){
            sl02();
          }
        });

        function right_Click() {
          $('.right').trigger('click');

        }

        function sl_Pre() {
          w01 = 0;
          w02 = 0;
          w03 = 1;
          $('.sl_img01').animate({left:'-100%'},1000);
          $('.sl_img02').animate({left:'-200%'},1000);
          $('.sl_img03').animate({left:'0%'},1000);
          $('.sl_img01').animate({left:'100%'},1000);


          sbtn_03();

        }

        function sl_Next() {

          w01 = 1;
          w02 = 0;
          w03 = 0;

          $('.sl_img03').animate({left:'-100%'},1000);
          $('.sl_img01').animate({left:'0%'},1000);
          $('.sl_img02').animate({left:'100%'},1000);
          $('.sl_img03').animate({left:'200%'},1000);

          sbtn_01();

        }

      function sl01 (){
        w01 = 1;
        w02 = 0;
        w03 = 0;

        $('.sl_img01').animate({left:'0%'},1000);
        $('.sl_img02').animate({left:'100%'},1000);
        $('.sl_img03').animate({left:'200%'},1000);

     sbtn_01();
      }


      function sl02 (){
        w01 = 0;
        w02 = 1;
        w03 = 0;
        $('.sl_img01').animate({left:'-100%'},1000);
        $('.sl_img02').animate({left:'0%'},1000);
        $('.sl_img03').animate({left:'100%'},1000);

        sbtn_02();


      }


      function sl03 (){
        w01 = 0;
        w02 = 0;
        w03 = 1;

        $('.sl_img01').animate({left:'-200%'},1000);
        $('.sl_img02').animate({left:'-100%'},1000);

        $('.sl_img03').animate({left:'0%'},1000);


        sbtn_03();


      }


      function sbtn_01() {
        $('.s_btn>li:nth-child(1)>a').css('background','#c00');
        $('.s_btn>li:nth-child(2)>a').css('background','#999');
        $('.s_btn>li:nth-child(3)>a').css('background','#999');


      }
      function sbtn_02() {
        $('.s_btn>li:nth-child(1)>a').css('background','#999');
        $('.s_btn>li:nth-child(2)>a').css('background','#c00');
        $('.s_btn>li:nth-child(3)>a').css('background','#999');

      }
      function sbtn_03(){
        $('.s_btn>li:nth-child(1)>a').css('background','#999');
        $('.s_btn>li:nth-child(2)>a').css('background','#999');
        $('.s_btn>li:nth-child(3)>a').css('background','#c00');


      }

    });

    </script>
    <div id="wrap">
      <div class="wrap_abs_slider">
        <div class="wrap_sl_rel">
          <img class="sl_img01" src="img/1.jpg" alt="">
          <img class="sl_img02" src="img/2.jpg" alt="">
          <img class="sl_img03" src="img/3.jpg" alt="">
        </div>
      </div>

      <div class="wrap_abs_con">
        <div class="wrap_con_rel">
          <button class="left">left</button>
          <button class="right">right</button>
          <ul class="s_btn">
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
            <li><a href="#"></a></li>
          </ul>
        </div>
      </div>
    </div>
  </body>
</html>

태그 연관 글
  1. [2016/11/01] 묻고답하기 wrap으로 감싼 부분이 height 100퍼센트가 원래 안되나요...? by Megg *4
  2. [2016/04/15] 묻고답하기 네비게이션바 관련 코딩 도움 부탁드립니다 by 범고래즈