#how to create responsive swipe cards

27 messages · Page 1 of 1 (latest)

tender tree
#

here I'm using css grid for the images. For mobile I want to transform this into swipe cards. what is the best way to achieve that?

compact tartan
#

can you explain a little bit more about what you mean by "swipe card"

tender tree
#

like this card slider

compact tartan
#

ah ok so basically a carousel

#

are you using vanilla HTML/CSS/JS?

tender tree
#

yes, with react passing data from json file

compact tartan
#

ok so you're using React, not vanilla JS?

compact tartan
#

ok basically, you need to take your array of all cards and slice it to a new array that only includes the ones visible at the moment

tender tree
#

okay

compact tartan
#
const visible = cards.slice(i, i + 3)
#

then you map over these and render them

#

plus some buttons that just increment and decrement i

tender tree
compact tartan
#

ok but you only need to show some of the cards at once

tender tree
compact tartan
#

you can't show all the cards at once

compact tartan
tender tree
#

okay

#

Thanks. 🍕

sour matrix
compact tartan
#

I probably should have mentioned using a package first

#

It’s a better idea than making your own if you’re looking to make a real product, but if you’re just trying to learn react then I’d suggest implementing it yourself

#

It doesn’t seem like you’re very far along in learning React, so building it yourself will help you get a little more practice

tender tree
#

I just used Swiper JS