Chuyển tới nội dung chính

Swiper

Swiper - tạo Slider cho Zalo Mini App. Bao gồm:

Properties

<Swiper/> properties

PropTypeDefaultDescription
classNamestringThêm css class cho element
styleReact.CSSPropertiesThêm inline style cho element
idstringElement id
paginationnumberẨn/Hiện phần phân trang
scrollbarbooleanẨn/Hiện scrollbar
navigationbooleanẨn/Hiện nút điều hướng
autoplaybooleanBật/Tắt tự động chuyển trang
allowSlideNextbooleanBật/Tắt cho phép chuyển trang kế tiếp
allowSlidePrevbooleanBật/Tắt cho phép chuyển trang trước
allowTouchMovebooleanBật/Tắt cho phép chuyển trang bằng nhấn và vuốt màn hình
centeredSlidesbooleanfalseBật/Tắt căn giữa slide đang kích hoạt
direction'horizontal' | 'vertical''horizontal'Slider theo chiều ngang hoặc dọc
effect'slide' | 'fade' | 'cube' | 'coverflow' | 'flip' | 'creative' | 'cards''slide'Hiệu ứng chuyển slide
enabledbooleantrue
loopbooleanfalseKhởi tạo với chế độ lặp
loopedSlidesnumberTrường hợp loop={true} slidesPerView='auto' đặt số lượng slide sẽ lặp
slidesPerViewnumber | 'auto'Số slide hiển thị trên một view
spaceBetweennumber0Khoảng cách giữa các slide (px)
speednumber300Thời gian chuyển slide (ms)
onSlideChangefunction(swiper)Event kích hoạt khi slide thay đổi

<SwiperSlide/> properties

PropTypeDefaultDescription
classNamestringThêm css class cho element
styleReact.CSSPropertiesThêm inline style cho element
idstringelement id

Swiper Instance Properties & Methods

Truy cập swiper instance thông qua css selector id:

<Swiper id='swiper-id' ref={swiperRef}></Swiper>
const swiper = zmp.swiper.get('swiper-id');
PropertiesDescription
activeIndexCho biết index của slide đang kích hoạt
allowSlideNextCho biết swiper có cho phép chuyển slide kế tiếp hay không
allowSlidePrevCho biết swiper có cho phép chuyển slide trước đó hay không
allowTouchMoveCho biết swiper có cho phép chuyển slide bằng nhấn, vuốt màn hình hay không
previousIndexCho biết index của slide trước đó
animatingCho biết trạng thái swiper đang chuyển slide hay không không
destroy(deleteInstance, cleanStyles)Huỷ swiper instance
disable()Vô hiệu hoá swiper
enable()Kích hoạt swiper
slideNext(speed, runCallbacks)Chuyển slide kế tiếp
slidePrev(speed, runCallbacks)Chuyển về slide trước đó
slideTo(index, speed, runCallbacks)Chuyển đến slide cụ thể theo index
update()Cập nhật lại swiper

Ví dụ

Code demo fallback when rendering server side!