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

home2 게시판 JavaScript, TS 게시판 캐러셀 스와이프 기능

캐러셀 스와이프 기능

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

    정은빈
    참가자
    안녕하세요. 혼자 해결해 보려고 했지만 도저히 모르겠어요ㅠㅠ. 스와이프가 안 됩니다.. 왜 인지 모르겠어요ㅜㅜ...
    
    
    
    <html>
    
    <div style="overflow: hidden;">
    <div class="slide-container">
    <div class="slide-box">
    < img src="img/car1.png" draggable="false">
    </div>
    <div class="slide-box">
    < img src="img/car2.png">
    </div>
    <div class="slide-box">
    < img src="img/car3.png">
    </div>
    </div>
    </div>
    <button class="before">Before</button>
    <button class="slide-1">1</button>
    <button class="slide-2">2</button>
    <button class="slide-3">3</button>
    <button class="next">Next</button>
    <script>
    
    
    $('.slide-1').on('click', function() {
    $('.slide-container').css('transform', 'translateX(0)');
     })
    $('.slide-2').on('click', function() {
    $('.slide-container').css('transform', 'translateX(-100vw)');
     })
    $('.slide-3').on('click', function() {
    $('.slide-container').css('transform', 'translateX(-200vw)');
     })
    // 다음 버튼 누르면
    // 지금 보이는 사진이 1이면 2번 사진 보여주세요
    var currentPhoto = 0;
    var totalPhotos = $('.slide-container .slide-box').length;
    console.log(totalPhotos);
    $('.next').on('click', function() {
    currentPhoto += 1;
    if (currentPhoto > totalPhotos) {
    currentPhoto = 0;
     }
    updateSlide();
    console.log(currentPhoto);
     })
     
    $('.before').on('click', function() {
    currentPhoto -= 1;
    if (currentPhoto < 0) {
    currentPhoto = totalPhotos - 1;
     }
    updateSlide();
    console.log(currentPhoto);
     })
    function updateSlide() {
    $('.slide-container').css('transform', 'translateX(-' + currentPhoto + '00vw)');
     }
    var startX = 0;
    var isMouseDown = false;
    $('.slide-box').eq(0).on('mousedown', function(e) {
    startX = e.clientX;
    isMouseDown = true;
     })
    $('.slide-box').eq(0).on('mousemove', function(e) {
    if ( isMouseDown ) {
    console.log(e.clientX - startX);
    $('.slide-container').css('transform', `translateX( ${e.clientX-startX} px)`);
     }
     })
    <css>
    
    .slide-container {
    width: 300vw;
    transition: all 1s;
    }
    .slide-box {
    width: 100vw;
    float: left;
    }
    .slide-box img {
    width: 100%;
    }
    
    
    #116393

    codingapple
    키 마스터
    translateX( ${e.clientX-startX} px)에 공백 지워봅시다
    #116436

    정은빈
    참가자
    감사합니다ㅠㅠ 바보같았네용
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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