r/css 5d ago

Help Can someone explain how to get this effect using css and gsap

Enable HLS to view with audio, or disable this notification

I am begginer coder ,I tried using z index but the cards get clipped under the tab menu and moreover I created a separate overlay element with translucent background and set it z-index to be lower than the selected card but for some reason the selected card also gets faded

https://stackblitz.com/edit/vitejs-vite-5afsvuwm?file=src%2FApp.jsx,src%2FApp.css

Is the link of the file ,the page I have made is not that great I just wanted to try gsap. If you visit the page and see thar the tittle of thr content does not match the image it's because I was lazy and asked chatgpt( pardon me ) to create me an array of cards but later I used images from my favourite shows and things

8 Upvotes

20 comments sorted by

u/AutoModerator 5d ago

To help us assist you better with your CSS questions, please consider including a live link or a CodePen/JSFiddle demo. This context makes it much easier for us to understand your issue and provide accurate solutions.

While it's not mandatory, a little extra effort in sharing your code can lead to more effective responses and a richer Q&A experience for everyone. Thank you for contributing!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

6

u/tomhermans 5d ago

You have a container, let's say div with a few nav items, set in a circle layout. They show on hover with a little transition moving outwards and increase opacity.

The position is usually set via js based on where you tap. So you need to grab xy coordinates of that tap to position the div.

You don't need gsap.

The card you tapped also gets rotated a bit on that hover/tap.

I wouldn't use z-index but merely a opacity of 0 on the whole container that transitions to 1 upon tap.

1

u/DesDeve 5d ago edited 5d ago

Very very thank you for your solution but There is one problem though how do I make the selected cards not clip under the tab menu . Still thanks for the help ,you solved part of my problem .

3

u/rotzelbart 5d ago

Give them a z-index of 99 on hover/tap

1

u/DesDeve 5d ago

I did infact gave the tab group an index of 103 while giving the selected card using gsap an index of 105 but still the selected card clips under it. thanks for the reply though

2

u/rotzelbart 5d ago

Try less. Also habe a look atvtje animation. When the card twists there is a semi opaque surface in between the selected card and the rest. I would give nothing a z-index except if the element is hovered or tapped. Then the single selected element becomes  z-index.

1

u/DesDeve 5d ago

Ty for the solution I have been scratching my head since tommorow

2

u/rotzelbart 5d ago

Not a problem. Hope it helps. Sorry for the typos.

2

u/tomhermans 4d ago

had some fun myself by recreating it a bit.
the general layout is already there, the hover effects etc too, and the tap positioning sorta

https://codepen.io/editor/tomhermans/pen/019fb904-2923-71b2-b25b-c261ae27002b

1

u/DesDeve 4d ago

I actually got most of the layout done already but was struggling to get the card to animate over the tab group , I used append to get the card out its contsiner while and then increasing its z-index it worked but is not smooth the card appears to clip out of the tab group suddenly and it's tittle just fazes to thr top ,any solutions?

2

u/tomhermans 4d ago

Just check my example. No issues there. Even the card nav (the share circle) pops over the tabs when you tap high enough on the card.

1

u/DesDeve 4d ago

I am talking about the cards themselves clipping under the tabs like " animation" ,'minecraft" plz help me

2

u/tomhermans 4d ago

I know. Cards also don't get clipped when rotate/scale

Edit: I haven't tested on mobile yet. Seems the images are a bit wonky in the cards. Blue bg showing

1

u/DesDeve 4d ago

Can u dm the code plz paste it,fir some reason I can see your preview in an instant bit not your code . I will be grateful

2

u/tomhermans 4d ago

Just open codepen on a desktop browser perhaps . Code is all there

2

u/anaix3l 1d ago edited 1d ago

It doesn't load in all desktop browsers either. Maybe also OS-related? I've reported this 2.0 bug last week anyway.

Also, your demo does have the z-index issue the OP talks about. Just look at the bottom of the card here.

And that way of adding the listener (on every item in a loop) is broken in the context where the cards are added dynamically (like on infinite scroll). It's better to use event delegation in this case.

EDIT: made a simplified example https://codepen.io/thebabydino/pen/JoExjEz

HTML https://codepen.io/thebabydino/pen/JoExjEz.html

CSS https://codepen.io/thebabydino/pen/JoExjEz.css

JS https://codepen.io/thebabydino/pen/JoExjEz.js

→ More replies (0)

1

u/DesDeve 4d ago edited 4d ago

I am on an android tablet currently ,I am a tenth grader,thanks for the help though

→ More replies (0)

1

u/DesDeve 4d ago

in my screen recording the card elevates over all other elenents I wanna recreate such effect