Swiper ์‚ฌ์šฉ ํ›„๊ธฐ (feat. ํ…Œ์ผ์œˆ๋“œ)

 

React์—์„œ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” Swiper๋Š” ์ด๋ฏธ์ง€ ์บ๋Ÿฌ์…€์„ ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์—์„œ Tailwind CSS์™€ ํ•จ๊ป˜ Swiper๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๋Š๋‚€ ์žฅ๋‹จ์ ์„ ์ •๋ฆฌํ•ด๋ณด์•˜๋‹ค.

 

 


 

์žฅ์ 

1. ์‚ฌ์šฉ์ด ๊ฐ„ํŽธํ•˜๋‹ค

Swiper๋Š” ๊ธฐ๋ณธ์ ์ธ ์„ค์ •๋งŒ์œผ๋กœ๋„ ์‰ฝ๊ฒŒ ์บ๋Ÿฌ์…€์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

์บ๋Ÿฌ์…€์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„์— <Swiper>๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ทธ ๋‚ด๋ถ€์— <SwiperSlide>๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค.

 

<Swiper>
  <SwiperSlide>Slide 1</SwiperSlide>
  <SwiperSlide>Slide 2</SwiperSlide>
</Swiper>

 

 

 

2. ๋ฌธ์„œํ™”๊ฐ€ ์ž˜๋˜์–ด์žˆ๋‹ค

Swiper๋Š” ๋ฌธ์„œ๊ฐ€ ์ž˜ ์ •๋ฆฌ๋˜์–ด ์žˆ๊ณ , ๋‹ค์–‘ํ•œ ์˜ˆ์ œ๋„ ์ œ๊ณต๋˜์–ด ์žˆ์–ด ์ฒ˜์Œ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ๋„ ์‰ฝ๊ฒŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

Swiper - The Most Modern Mobile Touch Slider

 

Swiper - The Most Modern Mobile Touch Slider

Swiper is the most modern free mobile touch slider with hardware accelerated transitions and amazing native behavior.

swiperjs.com

 

 

 

๋‹จ์ 

1. Tailwind์™€ ํ˜ธํ™˜์„ฑ์ด ๋†’์ง€ ์•Š๋‹ค

Swiper๋Š” Tailwind CSS์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ์— ๋ถˆํŽธํ•œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค.

ํ…Œ์ผ์œˆ๋“œ์˜ ๊ฒฝ์šฐ ํด๋ž˜์Šค๋ช…์„ ํ†ตํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ ์Šคํƒ€์ผ์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ์ ์ด ์žฅ์ ์ด ์žˆ๋‹ค. ํ•˜์ง€๋งŒ Swiper๋Š” CSS ์ž‘์—… ์‹œ.css ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด ์ง์ ‘ ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜ ์ธ๋ผ์ธ ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค์–ด:

.swiper{}
<Swiper
  ...
  style={{ width: '350px' }}
>

์ด๋Ÿฐ ์  ๋•Œ๋ฌธ์— ํ…Œ์ผ์œˆ๋“œ์˜ ๊ฐ„ํŽธํ•จ๊ณผ๋Š” ๋‹ค์†Œ ๊ฑฐ๋ฆฌ๊ฐ€ ์žˆ๋‹ค.

 

 

 

2. ๋‹ค๋ฅธ UI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ฐฐ์šฐ๋Š”๋ฐ ์‹œ๊ฐ„์ด ํ•„์š”ํ•˜๋‹ค

Swiper๋Š” ๋‹ค์–‘ํ•œ ์„ค์ •์„ ์ œ๊ณตํ•˜์ง€๋งŒ, ์ฒ˜์Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์„ค์ • ํ•ญ๋ชฉ๋“ค์„ ์ตํžˆ๋Š” ๋ฐ ์‹œ๊ฐ„์ด ํ•„์š”ํ•˜๋‹ค.

<Swiper
    spaceBetween={10}  // <- ์ด๋Ÿฐ ๋‚ด๋ถ€ ์„ค์ •๋“ค์ด ๋งŽ๋‹ค.
    centeredSlides
    pagination={{clickable: true,}}
    modules={[Autoplay]}
    autoplay={{ delay: 4000, disableOnInteraction: false }}
    loop
    slidesPerView={1}
    grabCursor
    onSlideChange={handleSlideChange}
    style={{ width: '350px' }}
>...</Swiper>

ํ•˜์ง€๋งŒ ์ด ๋ถ€๋ถ„์€ ์–ด์ฉ” ์ˆ˜ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค. ์˜คํžˆ๋ ค ์žฅ์ ์ด ๋  ์ˆ˜๋„..?

 

 

 

3. ํ…Œ์ŠคํŠธ ์„ค์ •์— ์ถ”๊ฐ€ ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค

ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์—์„œ Jest๋กœ ์ปดํฌ๋„ŒํŠธ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ ์ค‘์ธ๋ฐ, Swiper๊ฐ€ ํฌํ•จ๋œ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ ค๋ฉด ์˜ˆ์™ธ ์„ค์ •์„ ์ถ”๊ฐ€๋กœ ํ•ด์•ผํ–ˆ๋‹ค. (๊ทธ๋ƒฅ ๋‚ด๊ฐ€ Jest์— ์ต์ˆ™ํ•˜์ง€ ์•Š์•„์„œ ๊ทธ๋Ÿฐ ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ๋‹ค.)

๋ฌผ๋ก  Swiper๋งŒ์˜ ๋ฌธ์ œ๋ผ๊ธฐ๋ณด๋‹ค๋Š” UI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์˜ ๊ณตํ†ต์ ์ธ ์–ด๋ ค์›€์ผ ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ์ด ์ž‘์—…์ด ๋‚˜๋ฅผ ๋งค์šฐ ํž˜๋“ค๊ฒŒ ํ•œ๋‹ค.๐Ÿ˜ฅ

 

 


 

๊ฒฐ๋ก 

์ „์ฒด์ ์œผ๋กœ Tailwind CSS๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด Swiper ๋Œ€์‹  ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”์ฒœํ•˜๊ณ  ์‹ถ๋‹ค. ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋‚˜๋„ ๋ชจ๋ฅด๊ฒ ๋‹ค. (์ €์—๊ฒŒ ์ถ”์ฒœํ•ด์ฃผ์„ธ์š”..ใ…Žใ…Ž)

 

๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” css๋ฅผ ๋ณ„๋„๋กœ ์ž‘์„ฑํ•ด์•ผ ํ•˜๋Š” ์ ์ด ๋„ˆ๋ฌด ๋ถˆํŽธํ•˜๋‹ค. ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์—์„œ๋„ ์บ๋Ÿฌ์…€์„ ์ง์ ‘ ๊ตฌํ˜„ํ•ด๋ณผ๊นŒ ๊ณ ๋ฏผ ์ค‘์ด๋‹ค.

 

์ถ”๊ฐ€๋กœ Tailwind CSS๋กœ ์บ๋Ÿฌ์…€์„ ๊ตฌํ˜„ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ์•„๋ž˜ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜๊ธธ ์ถ”์ฒœํ•œ๋‹ค.

Scroll Snap Type - Tailwind CSS

 

Scroll Snap Type - Tailwind CSS

Utilities for controlling how strictly snap points are enforced in a snap container.

tailwindcss.com