ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

 

 

 

 

Today I Learned

 

 

๐Ÿ“Œ swiper.js๋กœ ๊ฐ„๋‹จํ•œ ๊ฐ€๋กœ ์Šฌ๋ผ์ด๋“œ ๋งŒ๋“ค๊ธฐ

 

๋‚ด๊ฐ€ ์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” ์‚ฌ์ „ ํ†ต๊ณ„ ํƒญ์— ๋‹จ์–ด ๋“ฑ๋ก์„ ๋งŽ์ด ํ•œ ์œ ์ € ๋žญํ‚น์ด ๋“ค์–ด๊ฐ€๋Š”๋ฐ,

์„ธ ๋ช…๊นŒ์ง€๋งŒ ๋‚˜์™€์„œ ์„ธ๋กœ๋กœ ๋Š˜์–ด๋†“๋Š” ๊ฒƒ ๋ณด๋‹ค๋Š” ๊ฐ€๋กœ๋กœ ์ˆœ์„œ๋Œ€๋กœ ๋ณด์ด๋Š” ๊ฒŒ ๋ชจ๋ฐ”์ผ ํ™˜๊ฒฝ์—์„œ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์•˜๋‹ค.

 

onMouse ์ด๋ฒคํŠธ๋กœ ์ด๋ ‡๊ฒŒ ์ €๋ ‡๊ฒŒ ํ•ด๋ณด๋‹ค๊ฐ€

์‹œ๊ฐ„์ด ์—†์–ด์„œ ๊ฒฐ๊ตญ ๋˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค.

 

swiper.js๋Š” ์ด๋ฏธ ๋‹ค๋ฅธ ํŽ˜์ด์ง€์—์„œ๋„ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์–ด์„œ ์„ค์น˜ํ•  ํ•„์š”๋Š” ์—†์—ˆ๊ณ ,

ํ•„์š”ํ•œ ๊ฒƒ๋งŒ ์ปดํฌ๋„ŒํŠธ์— import ํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉด ๋๋Š”๋ฐ

๋‚˜๋Š” ํŽ˜์ด์ง€๋„ค์ด์…˜๋„, ๋‚ด๋น„๊ฒŒ์ด์…˜๋„ ํ•„์š”ํ•˜์ง€ ์•Š๊ณ  ๊ฐ„๋‹จํ•œ ๊ฐ€๋กœ ์Šฌ๋ผ์ด๋“œ๋งŒ ๊ตฌํ˜„ํ•  ๊ฑฐ๋ผ์„œ

Swiper์™€ SwiperSlide๋งŒ importํ•ด์„œ ์‚ฌ์šฉํ–ˆ๋‹ค.

 

 

 

/* DictStat.js */

/* ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ import */

import { Swiper, SwiperSlide } from 'swiper/react'
import 'swiper/swiper.min.css'

/* ์ปดํฌ๋„ŒํŠธ์—์„œ ์Šฌ๋ผ์ด๋“œํ•  ๋ถ€๋ถ„ */

const DictStat = (props) => {
  return (
  /* ์ƒ๋žต */
    <StyledSwiper slidesPerView={2.16} spaceBetween={16} freeMode={true} lazy={true}>
      {rankList &&
        rankList.map((rank, index) => {
          return (
            <SwiperSlide key={`rank-${index}`}>
              <OneRankCard rank={rank} index={index} />
            </SwiperSlide>
          )
        })}
    </StyledSwiper>
    /* ์ƒ๋žต */
  )
}

/* styled-component๋กœ Swiper ์ปค์Šคํ…€ */

const StyledSwiper = styled(Swiper)`
  width: 100%;
  height: fit-content;
  padding: 16px;
  background-color: #eee !important;
  border-radius: 10px;
  cursor: grabbing;
  &::-webkit-scrollbar {
    display: none;
  }
  .swiper-slide {
    width: fit-content !important;
    background-color: transparent !important;
  }
`
export default DictStat

 

Swiper ์™€ SwiperSlide๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์ •ํ•˜๋Š” className๊ณผ ์†์„ฑ๋“ค์ด ์žˆ๋Š”๋ฐ,

๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์—์„œ๋„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๋ˆˆ์— ๋ณด์ด์ง€ ์•Š๋Š” ๊ธฐ๋ณธ className์ด ๊ฐ™์•„์„œ ์ถฉ๋Œ์ด ์ผ์–ด๋‚˜๊ธฐ๋„ ํ•œ๋‹ค.

 

๊ทธ๋ž˜์„œ ์›ฌ๋งŒํ•ด์„  className์„ ๋ณ„๋„๋กœ ์ง€์ •ํ•˜๊ฑฐ๋‚˜

์ ์šฉํ•˜๋ ค๋Š” css ์†์„ฑ์— ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ๊ฒƒ์ด ์šฐ์„ ์ ์œผ๋กœ ์ฐธ์กฐ๋  ์ˆ˜ ์žˆ๋„๋ก ! important ๋ฅผ ํ•จ๊ป˜ ์ž‘์„ฑํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

 

swiper ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ฒ˜์Œ ์‚ฌ์šฉํ•ด๋ดค๋Š”๋ฐ,

์ฐพ์•„๋ณด๋‹ˆ ํŽ˜์ด์ง€๋„ค์ด์…˜์ด๋‚˜ ๋‚ด๋น„๊ฒŒ์ด์…˜์„ ํ™œ์šฉํ•ด์„œ ์ฃผ๋กœ ๋ฐฐ๋„ˆ ์Šฌ๋ผ์ด๋“œ๋‚˜ ์บ๋Ÿฌ์…€ ์ด๋ฏธ์ง€์— ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

 

๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์—์„œ ์ฐพ์•„๋ณด๋‹ˆ ์ œ๊ณตํ•˜๋Š” API๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์•„์„œ ์˜คํžˆ๋ ค ํ˜ผ๋ž€์Šค๋Ÿฌ์› ๋Š”๋ฐ

์™ ์ง€ ์•ž์œผ๋กœ๋„ ์ž์ฃผ ์‚ฌ์šฉํ•  ๊ฒƒ ๊ฐ™์•„์„œ ํ•„์š”ํ•  ๋•Œ๋งˆ๋‹ค ๊ตฌ๊ธ€๋งํ•˜๊ธฐ ๋ณด๋‹ค๋Š” ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์—์„œ ์ฐพ์•„์„œ ํ•ด๊ฒฐํ•˜๋Š” ์—ฐ์Šต์„ ํ•ด์•ผ๊ฒ ๋‹ค!

 

 

 

๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Total
Today
Yesterday