I’m using React.js and swiper.js (https://swiperjs.com/)
Right now the swiper looks like this (https://codesandbox.io/s/swiper-react-forked-hkjwql?file=/src/index.js)
I wanna have white gradient on the side like this exemple. I tried to use CSS but it doesn’t work at all (https://codepen.io/studiojvla/pen/qVbQqW)
Here’s my code
My swiper component
<Swiper
spaceBetween={30}
loop={true}
slidesPerView={6}
centeredSlides={true}
speed={2000}
navigation={false}
modules={[Autoplay]}
grabCursor={true}
autoplay={{
delay: 500,
disableOnInteraction: false
}}
>
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((item) => {
return (
<SwiperSlide
key={item}
style={{
width: "100px",
height: "100px",
background: "red"
}}
>
<div>{item}</div>
</SwiperSlide>
);
})}
</Swiper>
How can I have this?
2
Answers
You can achieve that effect by applying these styles (copied from the Codepen) to your
swiper-container
element:You can see here the updated example.
I forked your example: https://codesandbox.io/s/swiper-react-forked-4p9dwx?file=/src/index.js
You can use two absolute divs to simulate your background gradient.
You can use it in combination with
pointer-events: none;
to allow dragging through the divs.