• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 JavaScript, TS 게시판 케러셀 스와이프 응용1번.

케러셀 스와이프 응용1번.

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #71205

    정창엽
    참가자
    var 시작좌표 = 0;
    var 누름 = false;
    $('.slide-box').on('mousedown', function(e){
        var id = e.target.dataset.id;
        console.log(e.target);
        console.log(id);
        시작좌표 = e.clientX;
        누름 = true;
        currentSlide(id);
    });
    function currentSlide(id){
        $('.slide-box').eq(id).on('mouseup', function(e){
            누름=false;
            console.log("넘어온 id 값" + id);
            console.log(e.clientX - 시작좌표);
            if(e.clientX - 시작좌표 < -300 && id == 0){
                console.log("id = 0");
                $('.slide-container').css('transition', 'all 0.5s').css('transform', 'translateX(-100vw)');
            }else if(e.clientX - 시작좌표 > -300 && id == 0){
                $('.slide-container').css('transition', 'all 0.5s').css('transform', `translateX(0vw)`);
            }else if(e.clientX - 시작좌표 < -300 && id == 1){
                $('.slide-container').css('transition', 'all 0.5s').css('transform', `translateX(-200vw)`);
            }else if(e.clientX - 시작좌표 > -300 && id == 1){
                $('.slide-container').css('transition', 'all 0.5s').css('transform', `translateX(-100vw)`);
            }
            // if((e.clientX - 시작좌표) < -300 && id == 1){
            //     console.log("id = 1");
            //     $('.slide-container').css('transition', 'all 0.5s').css('transform', 'translateX(-200vw)');
            // }else{
            //     $('.slide-container').css('transition', 'all 0.5s').css('transform', `translateX(-100vw)`);
            // }
            setTimeout(() =>{
                $('.slide-contatiner').css('transition', 'none');
                console.log("지움");
            },500)
        });
        $('.slide-box').eq(id).on('mousemove', function(e){
            console.log("여긴 무슨 값" + id, e.clientX - 시작좌표);
            if(누름==true){
                $('.slide-container').css('transform', `translateX(${e.clientX - 시작좌표}px)`);
            }
        });
    }
    dataset 이용해서 만들고 있습니다.
    
    dataset 값이 잘 넘어갈때도 있고, 처음 console.log(id)에선 1로 나오다가 
    currentSlide 함수에서 넘겨받은 값은 0으로 나올때도 있습니다.
    
    mousemove에서 id값 출력해보면 1이였다가 갑자기 0으로 출력됩니다.
    
    아마도 두번째사진(id 값 1)에서 클릭후 오른쪽으로 끌고가면 저절로 첫번째사진(id 값 0)
    으로 저절로 돌아가는거 때문에 그런거 같습니다.
    
    왜 첫번재 사진으로 돌아갈려는지 감이 안 오네요 ;;
    
    그리고 setTimeout 으로 transition none 해도 처음 빼고는 반응이 느립니다.
    
    
    #71253

    codingapple
    키 마스터
    마우스누를 때 마다 mouseup 이벤트리스너 부착하라고 코드짰는데 
    그러면 클릭100번하면 이벤트리스너도 100개 생겨서 이상해질걸요
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠