슬라이드다운 탭이 예상대로 작동하지 않음 (Slide-down tabs not working as expected)


문제 설명

슬라이드다운 탭이 예상대로 작동하지 않음 (Slide‑down tabs not working as expected)

저는 jQuery를 사용하여 사용자 정의 기반 탭을 만들었습니다. 규칙은 탭을 클릭하면 fadeIn 효과와 함께 콘텐츠가 아래로 슬라이드된다는 것입니다. 다른 탭을 클릭하면 slideUp이 아니라 fadeIn 효과와 함께 탭 2의 콘텐츠가 표시됩니다. 탭 2(이미 열려 있음)를 다시 클릭하면 탭 컨테이너가 위로 슬라이드됩니다.

처음에는 작동하지만 동일한 탭을 다시 클릭하면(슬라이드 후) 약간의 시간이 걸립니다. 미끄러지는 시간도 매끄럽지 않습니다.

내가 뭘 잘못하고 있는 걸까요?

  $(document).ready(function() {

    $('.tabs .col‑3 a').click(function(e) { // Or bind to any other event you like, or call manually

      e.preventDefault();
      var hrefid = $(this).attr("href");
      var tabid = ($(this).attr("href")).replace('#', ''); // remove #         

      var getContent = $(hrefid).html();

      $('#maintabcontent').hide().html(getContent).fadeIn(1400);


      $('span.plus').text("+");
      var $t = $('.tab‑container');

      if ($(this).parent().hasClass('active')) {
        $(this).find('span').text("+");
        $t.slideUp(function() {
          $('#maintabcontent').html('');
        });
        $(this).parent().removeClass('active');
      } else {

        $(this).find('span').text("‑");
        $t.slideDown(600, function() {

        });
        if ($t.is(':visible')) {
          $('.col‑3').removeClass('active');
          $(this).parent().addClass('active');
        }
      }

    });

  });
.container {
  margin: 0 auto;
  max‑width: 1280px;
  overflow: hidden;
  position: relative;
}
.full‑width {
  background: #dfdedb none repeat scroll 0 0;
  width: 100%;
}
.main‑container {
  margin: 0 auto;
  max‑width: 1220px;
}
.padding‑top‑bottom‑small {
  padding‑bottom: 1rem;
  padding‑top: 1rem;
}
.text‑center {
  text‑align: center;
}
.col‑3 {
  display: inline‑block;
  max‑width: 403px;
  overflow: hidden;
  position: relative;
  vertical‑align: top;
  width: 32.5%;
}
.tabs .col‑3 {
  border‑right: 2px solid #ffffff;
  cursor: pointer;
}
.tab‑container {
  background: #505050 none repeat scroll 0 0;
  display: none;
  position: relative;
}
.main‑container {
  margin: 0 auto;
  max‑width: 1220px;
}
.padding‑top‑bottom‑big {
  padding‑bottom: 2rem;
  padding‑top: 2rem;
}
.tab‑content {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="full‑width container tabs">
  <div class="main‑container">
    <div class="col‑3 first text‑center padding‑top‑bottom‑small"> <a href="#tab‑1"><h3 class="lato‑reg mediumfontx4 orange">How to Sell <span class="deep‑grey padding‑left‑tiny plus" data‑tab="tab‑1">+</span></h3></a>

    </div>
    <div class="col‑3 second text‑center padding‑top‑bottom‑small"> <a href="#tab‑2"><h3 class="lato‑reg mediumfontx4 orange">Finance <span class="deep‑grey padding‑left‑tiny plus" data‑tab="tab‑1">+</span></h3></a>

    </div>
    <div class="col‑3 text‑center padding‑top‑bottom‑small"> <a href="#tab‑3"><h3 class="lato‑reg mediumfontx4 orange">Market Intelligence <span class="deep‑grey padding‑left‑tiny plus" data‑tab="tab‑1">+</span></h3></a>

    </div>
  </div>
</div>
<div class="tab‑container">
  <div class="main‑container padding‑top‑bottom‑big" id="maintabcontent"></div>
</div>
<div id="tab‑1" class="tab‑content">Tab Content 1</div>
<div id="tab‑2" class="tab‑content">Tab Content 2</div>
<div id="tab‑3" class="tab‑content">Tab Content 3</div>

참조 솔루션

방법 1:

Add stop() before fadeIn():

$('#maintabcontent').hide().html(getContent).stop().fadeIn(1400);

That will stop any running animations and prevent the jerkiness you're experiencing.

Updated Fiddle

(by RajRick Hitchcock)

참조 문서

  1. Slide‑down tabs not working as expected (CC BY‑SA 2.5/3.0/4.0)

#tabs #jquery #slideDown






관련 질문

양식 제출 후 현재 탭 유지 (Keeping the current tabs after submitting the form)

슬라이드다운 탭이 예상대로 작동하지 않음 (Slide-down tabs not working as expected)

일부 장치 Android에서 ViewPager가 작동하지 않음 (ViewPager not working on some devices Android)

ScrollView가 조각에서 작동하지 않습니다 (ScrollView doesn't work in fragment)

공백이 많은 줄을 읽고 출력에서 유지 (Reading lines with a lot of spaces and maintaining them in output)

Google지도 조각을 찾을 수 없습니다 (Can't find google maps fragment)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

링크 클릭 시 새 탭 또는 창에서 특정 링크 열기 (Open specific link in new tab or window on link clicking)

Vue.js uiv 라이브러리의 Tab 구성 요소에 대한 클래스를 설정하는 방법은 무엇입니까? (How to set up classes for Vue.js uiv library's Tab component?)

Foundation 탭이 초기화되었는지 확인하는 방법은 무엇입니까? (How to check if Foundation tabs are initialized?)

고유 참조가 없는 한 HTML 페이지의 여러 탭(ID 또는 클래스 없음) (Multiple tabs in one HTML page without unique reference (no ID or class))

Angular Slickgrid 예제 24에서 Angular slickgrid 및 ngfor를 사용하여 동적으로 탭 만들기 (Dynamically create tabs with Angular slickgrid and ngfor in Angular Slickgrid Example 24)







코멘트