본문 바로가기
실전 코딩/플러그인

[swiper-slide] active 바뀔때 이벤트 주기

by 정리무새 2021. 9. 7.
728x90
반응형

나는 주로 슬라이드 플러그인을 swiper로 많이 쓰는데

active가 바뀔때마다 이벤트를 주었을때 사용한 방법이다.

 

방법은 두가지가 있는데

activeIndexChange는 활성화된 인덱스가 바뀔 때마다 호출되고,

slideChange는 활성화된 슬라이드(swiper-slide-active)가 바뀔 때마다 호출된다.

 

작업할 때 activeIndexChange는 반응하지 않아 slideChange를 사용하였다.

 

var mySwiper = new Swiper('.swiper-container', {
    slidesPerView: 'auto',
    centeredSlides: true,   
    on: {
        slideChange : function() {
            //이벤트 또는 조건문으로 이용하면 된다.
        },
    },
});

 

** 추가로 현재 인덱스를 사용하고 싶다면 slideChangeTransitionEnd를 이용하면 된다.

swiper event 쓰는 방법 : https://swiperjs.com/swiper-api#events

 

 

728x90
반응형

댓글