테스트 사이트 - 개발 중인 베타 버전입니다

슬라이드 스크립트

12132132132 5년 전 조회 6,570

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

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

 

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

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

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

 

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

뭐가 잘못된걸까요..?

 

 

 

</p>

<p><script src="<a href="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>" target="_blank" rel="noopener noreferrer">https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script></a></p>

<p>

<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></p>

<p>

<style>

* {

  margin: 0px;

  padding: 0px;

  background:#000

}</p>

<p>ul,

ol,

li {

  list-style: none;

}</p>

<p>a {

  text-decoration: none;

}</p>

<p>img {

  vertical-align: top;

  border: none;

}</p>

<p>.slide {

  position: relative;

  padding-top: 50px;

  overflow: hidden;</p>

<p>}</p>

<p>.panel {

  width: 400%;

}</p>

<p>.panel:after {

  content: "";

  display: block;

  clear: both;

}</p>

<p>.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

}</p>

<p>.panel>li:nth-of-type(1) {

  background-color: red;

}</p>

<p>.panel>li:nth-of-type(2) {

  background-color: blue;

}</p>

<p>.panel>li:nth-of-type(3) {

  background-color: green;

}</p>

<p>

.panel>li:nth-of-type(4) {

  background-color: #ffcc00;

}</p>

<p>.panel>li:nth-of-type(5) {

  background-color: #ededed;

}

.dot:after {

  content: "";

  display: block;

  clear: both;

}</p>

<p>.dot {

  position: absolute;

  left: 50%;

  bottom: 10%;

  transform: translateX(-50%);

}</p>

<p>.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;

}</p>

<p>.dot>li.on {

  background-color: #342f2f;

}</p>

<p></style></p>

<p><script>

$(document).ready(function() {

  slide();

});</p>

<p>

// 슬라이드 

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');</p>

<p>  // 변수 초기화

  function init() {

    wid = $('.slide').width();

    now_num = $('.dot>li.on').index();

    slide_length = $dotli.length;

  }</p>

<p>  // 이벤트 묶음

  function slideEvent() {</p>

<p>    // 슬라이드 하단 dot버튼 클릭했을때

    $dotli.click(function() {

      now_num = $(this).index();

      slideMove();

    });</p>

<p>

    // 오토플레이

    autoPlay();</p>

<p>    // 오토플레이 멈춤

    autoPlayStop();</p>

<p>    // 오토플레이 재시작

    autoPlayRestart();</p>

<p>    // 화면크기 재설정 되었을때

    resize();

  }</p>

<p> // 자동실행 함수

  function autoPlay() {

    auto = setInterval(function() {

      nextChkPlay();

    }, 3000);

  }</p>

<p>  // 자동실행 멈춤

  function autoPlayStop() {

    $panelLi.mouseenter(function() {

      clearInterval(auto);

    });

  }</p>

<p>

 // 자동실행 멈췄다가 재실행

  function autoPlayRestart() {

    $panelLi.mouseleave(function() {

      auto = setInterval(function() {

        nextChkPlay();

      }, 3000);

    });

  }</p>

<p>

 // 슬라이드 무브

  function slideMove() {

    $panel.stop().animate({

      'margin-left': -wid * now_num

    });

    $dotli.removeClass('on');

    $dotli.eq(now_num).addClass('on');

  }</p>

<p>// 화면크기 조정시 화면 재설정

  function resize() {

    $(window).resize(function() {

      init();

      $panel.css({

        'margin-left': -wid * now_num

      });

    });

  }

  init();

  slideEvent();

}

</script></p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

5년 전

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

 

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

 

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

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인