슬라이드 스크립트

슬라이드 스크립트

QA

슬라이드 스크립트

본문

쇼핑몰 슬라이드 스크립트인데 

제가 코알못이라 ㅠㅠ 어렵네요..

 

4번째 슬라이드까진 문제없이 나오는데

5번째 슬라이드가  자꾸 밖으로 나와서 .slide에 높이값을 지정하면

5번 이미지가 overflow:hidden때문에 아예 안나오더라구요..

 

5번도 나머지 탭들처럼 문제없이 나왔으면 좋겠어요 ㅠㅠ

뭐가 잘못된걸까요..?

 

 

 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<div class="slide">
  <ul class="panel">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
  </ul>
  <ul class="dot">
    <li class="on">1번 탭</li>
        <li>2번 탭</li>
        <li>3번 탭</li>
        <li>4번 탭</li>
        <li>5번 탭</li>
   </ul>
</div>

<style>
* {
  margin: 0px;
  padding: 0px;
  background:#000
}
ul,
ol,
li {
  list-style: none;
}
a {
  text-decoration: none;
}
img {
  vertical-align: top;
  border: none;
}
.slide {
  position: relative;
  padding-top: 50px;
  overflow: hidden;
}
.panel {
  width: 400%;
}
.panel:after {
  content: "";
  display: block;
  clear: both;
}
.panel>li {
  width: 25%;
  height: 750px;
  float: left;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  position: relative;
  font-size:30px;
  text-align:center;
  color:#fff
}
.panel>li:nth-of-type(1) {
  background-color: red;
}
.panel>li:nth-of-type(2) {
  background-color: blue;
}
.panel>li:nth-of-type(3) {
  background-color: green;
}

.panel>li:nth-of-type(4) {
  background-color: #ffcc00;
}
.panel>li:nth-of-type(5) {
  background-color: #ededed;
}
.dot:after {
  content: "";
  display: block;
  clear: both;
}
.dot {
  position: absolute;
  left: 50%;
  bottom: 10%;
  transform: translateX(-50%);
}
.dot>li {
  float: left;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background-color: #fff;
  margin-left: 10px;
  margin-right: 10px;
  text-indent: -9999px;
  cursor: pointer;
}
.dot>li.on {
  background-color: #342f2f;
}
</style>
<script>
$(document).ready(function() {
  slide();
});

// 슬라이드 
function slide() {
  var wid = 0;
  var now_num = 0;
  var slide_length = 0;
  var auto = null;
  var $dotli = $('.dot>li');
  var $panel = $('.panel');
  var $panelLi = $panel.children('li');
  // 변수 초기화
  function init() {
    wid = $('.slide').width();
    now_num = $('.dot>li.on').index();
    slide_length = $dotli.length;
  }
  // 이벤트 묶음
  function slideEvent() {
    // 슬라이드 하단 dot버튼 클릭했을때
    $dotli.click(function() {
      now_num = $(this).index();
      slideMove();
    });

    // 오토플레이
    autoPlay();
    // 오토플레이 멈춤
    autoPlayStop();
    // 오토플레이 재시작
    autoPlayRestart();
    // 화면크기 재설정 되었을때
    resize();
  }
 // 자동실행 함수
  function autoPlay() {
    auto = setInterval(function() {
      nextChkPlay();
    }, 3000);
  }
  // 자동실행 멈춤
  function autoPlayStop() {
    $panelLi.mouseenter(function() {
      clearInterval(auto);
    });
  }

 // 자동실행 멈췄다가 재실행
  function autoPlayRestart() {
    $panelLi.mouseleave(function() {
      auto = setInterval(function() {
        nextChkPlay();
      }, 3000);
    });
  }

 // 슬라이드 무브
  function slideMove() {
    $panel.stop().animate({
      'margin-left': -wid * now_num
    });
    $dotli.removeClass('on');
    $dotli.eq(now_num).addClass('on');
  }
// 화면크기 조정시 화면 재설정
  function resize() {
    $(window).resize(function() {
      init();
      $panel.css({
        'margin-left': -wid * now_num
      });
    });
  }
  init();
  slideEvent();
}
</script>

이 질문에 댓글 쓰기 :

답변 1

nextChkPlay 라는 함수가 정의 안되어 있네요..

 

슬라이드는 다양한 것을 지원하는 https://swiperjs.com/demos/

 

이런것을 사용하는 것이 편할것 같습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 1,098
QA 내용 검색
filter #html ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT