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 |
Tags
- 개발공부
- 날씨 웹 만들기
- JavaScript
- 코딩부트캠프
- 코드스테이츠
- [파이썬 실습] 기초 문제
- 자바스크립트 날씨 웹 만들기
- 자바스크립트 split()
- HTML
- [AI 5기] 연습 문제집
- 자바스크립트
- 부트캠프
- reactnativecli
- 개발일기
- 자바스크립트 날씨
- 간단한 날씨 웹 만들기
- 엘리스 ai 트랙
- RN 프로젝트
- 프론트개발공부
- 프로그래머스
- 엘리스
- 자바스크립트 reduce()
- [파이썬 실습] 중급 문제
- 삼항연산자
- leetcode
- 프론트개발
- 리트코드
- 엘리스 AI 트랙 5기
- 자바스크립트 sort()
- [파이썬 실습] 심화 문제
Archives
- Today
- Total
개발조각
[Swiper & React] Swiper로 화면 밖에 navigation 만드는 방법 본문
728x90
반응형
만들고 싶은 슬라이드

문제점
앞서 작성한 pagination과 같이 swiper의 hidden 때문에
swiper옵션으로 navigation을 적용하고 navigation을 밖으로 빼서 사용하면 navigation이 안 보이는 현상이 발생한다.
<>
<Swiper navigation={true} modules={[Navigation]} className="mySwiper">
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
<SwiperSlide>Slide 4</SwiperSlide>
<SwiperSlide>Slide 5</SwiperSlide>
<SwiperSlide>Slide 6</SwiperSlide>
<SwiperSlide>Slide 7</SwiperSlide>
<SwiperSlide>Slide 8</SwiperSlide>
<SwiperSlide>Slide 9</SwiperSlide>
</Swiper>
</>
해결방안
import React, { useRef, useState } from 'react';
// Import Swiper React components
import { Swiper, SwiperSlide } from 'swiper/react';
// Import Swiper styles
import 'swiper/css';
import 'swiper/css/navigation';
import './styles.css';
// import required modules
import { Navigation } from 'swiper/modules';
export default function App() {
const [swiper, setSwiper] = useState(null);
return (
<>
<div className="navigation-btn-wrap">
<button onClick={() => swiper.slidePrev()}>{icon.navigationPrev}</button>
<button onClick={() => swiper.slideNext()}>{icon.navigationNext}</button>
</div>
<div>
<Swiper //
navigation={true}
modules={[Navigation]}
onBeforeInit={(swipper) => setSwiper(swipper)}
className="mySwiper"
>
<SwiperSlide>Slide 1</SwiperSlide>
<SwiperSlide>Slide 2</SwiperSlide>
<SwiperSlide>Slide 3</SwiperSlide>
<SwiperSlide>Slide 4</SwiperSlide>
</Swiper>
<div>
</>
);
}
onBeforeInit : 초기화 직후 이벤트가 시작됩니다.
참고 자료
Swiper Navigator(화살표) 바깥으로 빼기
프로젝트 KKu-Woon을 진행하며 유저 리스트를 carousel 형식으로 구현해야 상황이 있었습니다. 프로젝트 기간이 여유롭지 않고, 캐러셀은 라이브러리로 잘 만들어져 있기 때문에 오픈 소스를 사용하
hoime.tistory.com
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로 두개의 슬라이드 동시에 제어하기 (0) | 2023.09.10 |
| [Swiper & React] Swiper로 화면 밖에 pagination 만드는 방법 (0) | 2023.09.10 |
Comments