๐ŸŸฉ Frontend-HTML & CSS & +JS/๐Ÿ”ฐ React

๋ฆฌ์•กํŠธ์— swiper ์“ฐ๋Š” ์˜ˆ์ œ (dom ๋ฒ„์ „ ์˜ค๋ฅ˜ํ•ด๊ฒฐ๋ฒ•) (React swiper)

ramen2 2024. 12. 27. 00:21
๋ฐ˜์‘ํ˜•

| ์„ค์น˜ ๋ฐ ๊ธฐ๋ณธ ์‚ฌ์šฉ ์˜ˆ

https://swiperjs.com/react#use-swiper-slide

 

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. React์™€ React-DOM ํŒจํ‚ค์ง€๋ฅผ ์•„๋ž˜ ๋ฒ„์ „์œผ๋กœ ์„ค์น˜ 

npm install react@18 react-dom@18

 

โ€ป ๋งŒ์•ฝ, ์ด์ „ ๋ฒ„์ „์ด ๋‚ฎ๊ฑฐ๋‚˜ ๋†’์•„์„œ ์‚ฌ์šฉ์ด ์•ˆ๋œ๋‹ค๋ฉด, ์•„๋ž˜ ์ฝ”๋“œ๋กœ ์‚ญ์ œํ›„ ์œ„ ์ฝ”๋“œ๋กœ ๋‹ค์‹œ ์„ค์น˜

npm uninstall react react-dom

 

 

2. Swiper ์„ค์น˜

  npm i swiper

 

 

3. Swiper ์‚ฌ์šฉํ•  jsx์— ์ฝ”๋“œ ์ž…๋ ฅ 

// Import Swiper React components
import { Swiper, SwiperSlide } from 'swiper/react';

// Import Swiper styles
import 'swiper/css';

export default () => {
  return (
    <Swiper
      spaceBetween={50}
      slidesPerView={3}
      onSlideChange={() => console.log('slide change')}
      onSwiper={(swiper) => console.log(swiper)}
    >
      <SwiperSlide>Slide 1</SwiperSlide>
      <SwiperSlide>Slide 2</SwiperSlide>
      <SwiperSlide>Slide 3</SwiperSlide>
      <SwiperSlide>Slide 4</SwiperSlide>
      ...
    </Swiper>
  );
};

 

 

 

** ํŽ˜์ด์ง€ ๋„ค์ด์…˜, ์˜คํ† ํ”Œ๋ ˆ์ด ๋“ฑ์˜ ํšจ๊ณผ๋ฅผ ๋„ฃ์€ ์˜ˆ์ œ

์˜ˆ์ œ ๊ฒฐ๊ณผ

import React, { useContext, useState} from "react";
import styles from './Home.module.css';

/* ์Šฌ๋ผ์ด๋“œ swiper */
// Import Swiper React components
import { Swiper, SwiperSlide } from 'swiper/react';
// Import Swiper styles
import 'swiper/css';
import 'swiper/css/navigation';
import 'swiper/css/pagination';
import 'swiper/css/scrollbar';
// import Swiper core and required modules
import { Navigation, Pagination, Scrollbar , Autoplay, A11y } from 'swiper/modules';






function Home() {
    return(
        // <div className={styles.Home}>
        <Swiper
        // install Swiper modules
        modules={[Navigation, Pagination, Scrollbar, Autoplay, A11y]}
        spaceBetween={50}
        slidesPerView={3}
        navigation
        pagination={{ clickable: true }}
        onSwiper={(swiper) => console.log(swiper)}
        onSlideChange={() => console.log('slide change')}
        autoplay= {{delay:2000}}
      >
        <SwiperSlide>Slide 1</SwiperSlide>
        <SwiperSlide>Slide 2</SwiperSlide>
        <SwiperSlide>Slide 3</SwiperSlide>
        <SwiperSlide>Slide 4</SwiperSlide>
      </Swiper>
        
    )

    
    
};


export default Home;

 

๋ฐ˜์‘ํ˜•