๐Ÿ“บ React Slick์œผ๋กœ ์บ๋Ÿฌ์…€ ๊ตฌํ˜„ํ•˜๊ธฐ, ์ปค์Šคํ…€ ํ™”์‚ดํ‘œ

์ง€์€ยท2023๋…„ 4์›” 6์ผ
0

๐ŸŒด ๋ชจ๋™์ˆฒ ๋งˆ์ผ“

๋ชฉ๋ก ๋ณด๊ธฐ
4/9
post-thumbnail

React Slick์€ ์บ๋Ÿฌ์…€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋‹ค.

์„ค์น˜

npm install react-slick --save

import

import Slider from 'react-slick';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';

์‚ฌ์šฉํ•˜๋Š” ๋ฒ•

settings ๊ฐ์ฒด๋ฅผ ์ •์˜ํ•ด์ค€๋‹ค์Œ Slider ๊ฐ์ฒด์— ์ „๋‹ฌํ•˜๋ฉด ๋œ๋‹ค. ๋‚ด๊ฐ€ ์“ด ๊ฒƒ ์™ธ์—๋„ ์—„์ฒญ ๋‹ค์–‘ํ•œ ์˜ต์…˜์ด ์žˆ๋‹ค.

const Carousel = () => {
	const settings = {
		dots: true,          // ์บ๋Ÿฌ์…€ ๋ฐ‘์— ... ์„ ํ‘œ์‹œํ• ์ง€
		infinite: true,      // ์Šฌ๋ผ์ด๋“œ๊ฐ€ ๋๊นŒ์ง€ ๊ฐ€๋ฉด ๋‹ค์‹œ ์ฒ˜์Œ์œผ๋กœ ๋ฐ˜๋ณต
		speed: 3000,         // ์†๋„
		autoplay: true,      // ์ž๋™ ์žฌ์ƒ
		autoplaySpeed: 3000, // ์ž๋™ ์žฌ์ƒ ์†๋„
		slidesToShow: 1,     // ํ•œ ๋ฒˆ์— ๋ณด์—ฌ์ค„ ์Šฌ๋ผ์ด๋“œ ๊ฐœ์ˆ˜
		slidesToScroll: 1,   // ํ•œ ๋ฒˆ์— ๋„˜์–ด๊ฐ€๋Š” ์Šฌ๋ผ์ด๋“œ ๊ฐœ์ˆ˜
        nextArrow: <NextArrow />, // ํ™”์‚ดํ‘œ ๋ฒ„ํŠผ์„ ์ปค์Šคํ…€ํ•ด์„œ ์‚ฌ์šฉ
		prevArrow: <PrevArrow />,
	};

	return (
		<div>
			<Slider {...settings}> // <-- settings ์ „๋‹ฌ
				<div className='h-56 bg-sky-100'>
					<img src='image/1' />
				</div>
				<div className='h-56 bg-pink-100'>
					<img src='image/2' />
				</div>
				<div className='h-56 bg-yellow-100'>
					<img src='image/3' />
				</div>
				<div className='h-56 bg-red-100'>
					<img src='image/4' />
				</div>
				<div className='h-56 bg-purple-100'>
					<img src='image/5' />
				</div>
			</Slider>
		</div>
	);
};
                                        
const NextArrow = ({ onClick }) => { // props๋กœ onClick์„ ์ „๋‹ฌํ•ด์ค˜์•ผ ํ•œ๋‹ค.
	return (
		<button
			onClick={onClick}
			type='button'
		>
		... ์ƒ๋žต
		</button>
	);
};

const PrevArrow = ({ onClick }) => {
	return (
		<button
			onClick={onClick}
			type='button'
		>
		... ์ƒ๋žต
		</button>
	);
};

์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์ด ์•„๋ฆ„๋‹ค์šด ์บ๋Ÿฌ์…€์ด ๋œ๋‹ค!
์ง„์ž‘ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์“ธ๊ฑธ ์™œ ์บ๋Ÿฌ์…€ ์ง์ ‘ ๋งŒ๋“ค๊ฒ ๋‹ค๊ณ  ๋™๋™๋Œ”์—ˆ๋Š”์ง€... ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋‹ค๋ฉด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ์ž๐Ÿ˜‚

profile
๋ธ”๋กœ๊ทธ ์ด์ „ -> https://janechun.tistory.com

5๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 4์›” 8์ผ

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์œผ๋ฉด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ์ž..๋ฉ”๋ชจ ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ์ทจ์—…์„ ์œ„ํ•ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—†์ด ํ•˜๋Š” ๊ฑธ ์—ฐ์Šตํ–ˆ๋‹ค ์ƒ๊ฐํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ
comment-user-thumbnail
2023๋…„ 4์›” 8์ผ

์œ ์šฉํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ž˜ ๋ณด๊ณ  ๊ฐ‘๋‹ˆ๋‹ค !

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ
comment-user-thumbnail
2023๋…„ 4์›” 9์ผ

๋ชจ๋™์ˆฒ ์ง„์งœ ์ข‹์•„ํ•˜์‹œ๋Š” ๊ตฐ์š” ใ…‹ใ…‹ใ…‹ ์บ๋Ÿฌ์…€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ž˜ ๋ณด๊ณ  ๊ฐ‘๋‹ˆ๋‹ค

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ

์žˆ๋Š”๊ฑฐ ์“ฐ๋Š”๊ฒŒ ์ตœ๊ณ ๊ธด ํ•ด์š” ... ใ…‹ใ…‹ใ…‹

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ
comment-user-thumbnail
2023๋…„ 4์›” 9์ผ

์•— ๋ชจ๋™์ˆฒ... ์ด๊ณณ์— ๊ณ„์…จ๊ตฐ์š”,.ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ์ข‹์€ ์ •๋ณด ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ