Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 간단한 날씨 웹 만들기
- [파이썬 실습] 기초 문제
- 자바스크립트 reduce()
- 삼항연산자
- 자바스크립트 날씨
- 프로그래머스
- 자바스크립트 split()
- 자바스크립트 sort()
- 개발일기
- 날씨 웹 만들기
- 엘리스 ai 트랙
- [파이썬 실습] 심화 문제
- 엘리스
- reactnativecli
- RN 프로젝트
- 코딩부트캠프
- leetcode
- 프론트개발
- 부트캠프
- JavaScript
- 개발공부
- 프론트개발공부
- [파이썬 실습] 중급 문제
- 코드스테이츠
- [AI 5기] 연습 문제집
- 엘리스 AI 트랙 5기
- 리트코드
- 자바스크립트
- 자바스크립트 날씨 웹 만들기
- HTML
Archives
- Today
- Total
개발조각
[Swiper & React] Swiper로 두개의 슬라이드 동시에 제어하기 본문
728x90
반응형
만들고 싶은 슬라이드
슬라이드를 만들다 보면 각각의 다른 슬라이드를 제어를 하고 싶은 경우가 생기게 됩니다.
1번 슬라이드를 기준으로 1번 슬라이드가 움직이면 2번 슬라이드도 같이 움직이는 슬라이드를 만드는 방법입니다.
문제점
처음에는 아래의 예제를 참고해서 만들었으나
pagination, autoplay, loop를 적용하면 이상하게 동작하는 현상이 발생
https://codesandbox.io/s/k3cyyc?file=/src/App.jsx
swiper-react-thumbs-gallery - CodeSandbox
swiper-react-thumbs-gallery using react, react-dom, swiper
codesandbox.io
해결방안
Thumbs를 사용하면 안 되고 Controller를 사용해야 된다.
import React, { useRef, useState } from 'react';
// Import Swiper React components
import { Swiper, SwiperSlide } from 'swiper/react';
// Import Swiper styles
import 'swiper/css';
import './styles.css';
// import required modules
import { Autoplay, Controller } from 'swiper/modules';
export default function App() {
const [firstSwiper, setFirstSwiper] = useState(null);
const [secondSwiper, setSecondSwiper] = useState(null);
return (
<>
<Swiper //
autoplay={{ delay: 2000, disableOnInteraction: false }}
loop={true}
modules={[Controller, Pagination, Autoplay]}
onSwiper={setFirstSwiper}
controller={{ control: secondSwiper }}
className="mySwiper"
>
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
<SwiperSlide>Slide 4</SwiperSlide>
</Swiper>
<Swiper //
modules={[Controller]}
loop={true}
onSwiper={setSecondSwiper}
controller={{ control: firstSwiper }}
className="mySwiper2"
>
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
<SwiperSlide>Slide 4</SwiperSlide>
</Swiper>
</>
);
}
728x90
반응형
'라이브러리' 카테고리의 다른 글
[recoil, recoil-persist] 로그인 구현시 recoil-persist로 storage에 토큰 넣기 (0) | 2023.12.19 |
---|---|
[react-device-detect & video-react] 비디오 배경만들때 pc일때는 pc비디오, mobile일때는 mobile비디오 나오게 하기 (0) | 2023.09.21 |
[react-device-detect] 각 디바이스마다 맞는 스토어 이동기능 구현하기 (0) | 2023.09.21 |
[Swiper & React] Swiper로 화면 밖에 navigation 만드는 방법 (0) | 2023.09.10 |
[Swiper & React] Swiper로 화면 밖에 pagination 만드는 방법 (0) | 2023.09.10 |
Comments