스크립트 질문 입니다.

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
스크립트 질문 입니다.

QA

스크립트 질문 입니다.

본문

이전 다음 버튼 구현 중인데

순차적으로 되어야 되는데 먼가 중간 객체를 건너띄는 현상이 있는데 어디가 잘못된걸까요?

 

저 부분이 2가 되어야 되는데 이상하네요.

32936023_1714636362.6245.png

 


$('.tabBtn_next').click(function(){
        
        $(".newsWrapWrap .newsWrap").removeClass('active');
        if($(".tabItem > .item:nth-child(1)")) {
            $(".newsWrapWrap .newsWrap").removeClass('active');
            $(".newsWrapWrap > .newsWrap:nth-child(1)").addClass('active');
        }
        if($(".tabItem > .item:nth-child(2)")) {
            $(".newsWrapWrap .newsWrap").removeClass('active');
            $(".newsWrapWrap > .newsWrap:nth-child(2)").addClass('active');
        }
        if($(".tabItem > .item:nth-child(3)")) {
            $(".newsWrapWrap .newsWrap").removeClass('active');
            $(".newsWrapWrap > .newsWrap:nth-child(3)").addClass('active');
        }
        
        $('.tabItem').find('.active').next().addClass('active');
        $('.tabItem').find('.active').prev().removeClass('active');
        //console.log(tab_num);
    });
    $('.tabBtn_prev').click(function(){
        
        $(".newsWrapWrap .newsWrap").removeClass('active');
        if($(".tabItem > .item:nth-child(3)")) {
            $(".newsWrapWrap .newsWrap").removeClass('active');
            $(".newsWrapWrap > .newsWrap:nth-child(3)").addClass('active');
        }
        if($(".tabItem > .item:nth-child(2)")) {
            $(".newsWrapWrap .newsWrap").removeClass('active');
            $(".newsWrapWrap > .newsWrap:nth-child(2)").addClass('active');
        }
        if($(".tabItem > .item:nth-child(1)")) {
            $(".newsWrapWrap .newsWrap").removeClass('active');
            $(".newsWrapWrap > .newsWrap:nth-child(1)").addClass('active');
        }
        
        $('.tabItem').find('.active').prev().addClass('active');
        $('.tabItem').find('.active').next().removeClass('active');
        //console.log(tab_num);
    });

이 질문에 댓글 쓰기 :

답변 2


$('.tabBtn_next').click(function(){
    next++;
    if(next == $(".tabItem > .item").length){
        next = 0;
    }
    $(".newsWrapWrap .newsWrap").removeClass("active").eq(next).addClass("active");
})
let prev = 0;
$('.tabBtn_prev').click(function(){
    prev--;
    if(prev == -1){
        prev = $(".tabItem > .item").length-1;
    }
    $(".newsWrapWrap .newsWrap").removeClass("active").eq(prev).addClass("active");
})

 

전체 코드 및 예제 사이트가 (구조를 정확하게 몰라) 없어서 올려주신 코드 분석 해서 작성했습니다.

위 코드로는 100% 정확한 답변을 알수 없어요.

그냥 각 페이지별로 인덱스를 부여하셔서 작업하세요..

add 와 remove 조합이면 많이 조잡해보입니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 124,365
QA 내용 검색

회원로그인

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