swiper 재생, 정지 자바스크립트

Mori·2022년 4월 12일
1

슬라이더

목록 보기
2/2

자바스크립트, 제이쿼리 사용할 적에
swiper 재생, 정지를 다룬적이 있는데
코드를 올려 본다.


<script>
var mySwiper = new Swiper('.swiper-container', {
  // Optional parameters
  //direction: 'vertical',
  loop: true,
  autoplay:{
                delay:1000 //1초의 딜레이를 주고 자동 재생된다
            },
  

  // If we need pagination
  pagination: {
    el: '.swiper-pagination',
  },

  // Navigation arrows
//   navigation: {
//     nextEl: '.swiper-button-next',
//     prevEl: '.swiper-button-prev',
//   },

  // And if we need scrollbar
  scrollbar: {
    el: '.swiper-scrollbar',
  },
})
var sw = 0;
$('.btn_pause').click(function(){
    if(sw==0){
        $('.btn_pause').addClass('on');
        mySwiper.autoplay.stop();
        sw = 1;
    }else{
        $('.btn_pause').removeClass('on');
        mySwiper.autoplay.start();
        sw = 0;
    }
});

});

</script>```

0개의 댓글