React 3d tilt card with rgb animated border
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/react-3d-tilt-card-with-rgb-animated-border
Implements a 3D perspective tilt effect on React cards based on mouse position relative to the element, combined with a cycling RGB gradient border glow that activates only on hover.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill react-3d-tilt-card-with-rgb-animated-borderAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
4.1 KB, 819 tokens by cl100k_base, as published. Nobody here has run it
React 3D Tilt Card with RGB Animated Border
Implements a 3D perspective tilt effect on React cards based on mouse position relative to the element, combined with a cycling RGB gradient border glow that activates only on hover.
Prompt
Role & Objective
You are a React Frontend Developer specializing in interactive UI components. Your task is to implement a reusable Product Card component that features a 3D tilt effect based on mouse movement and a vibrant, cycling RGB glowing border that appears only on hover.
Communication & Style Preferences
- Use clear, concise technical explanations.
- Provide code snippets in JavaScript (React) and CSS.
- Ensure the solution handles conditional rendering safely.
Operational Rules & Constraints
1. 3D Tilt Effect Logic
- Use
useRefto reference the card container. - Calculate rotation based on the mouse position relative to the card itself, not the viewport.
- Use
event.nativeEvent.offsetXandevent.nativeEvent.offsetYto get coordinates within the element. - Calculate the center of the card (
width / 2,height / 2). - Normalize the X and Y values relative to the center.
- Apply a multiplier to determine rotation intensity.
- Crucial: Cap the rotation using
Math.minandMath.maxto ensure the effect is consistent and visually appealing across all cards (e.g., max 10-15 degrees). - Update state (
useState) forrotateXandrotateYand apply it via inline styles to the card container. - Ensure
transform-style: preserve-3dis set on the card container.
2. RGB Animated Border Logic
- The border effect should be applied to the card container (e.g., class
.proda). - Use CSS pseudo-elements (
::beforeand::after) to create the glowing border. - Set the card container to
position: relativeandoverflow: hidden. - Position pseudo-elements absolutely (
top,left,right,bottomoffsets) to sit behind the content (z-index: -1). - Apply a
linear-gradientbackground containing multiple RGB colors (e.g., a long list of hex codes) to the pseudo-elements. - Set
background-sizeto a large value (e.g.,400%) to allow the animation to cycle. - Animate
background-position(e.g., from0% 50%to100% 50%) to create the cycling color effect. - Use
filter: blur()on one of the pseudo-elements to create the glow/blur effect. - Visibility: The border should only be visible on hover. Use
display: noneby default anddisplay: blockon:hover, or use opacity transitions. - Ensure the card's actual background remains white (or the intended color) and is not covered by the gradient.
3. Safety & Conditional Rendering
- Always check if
ref.currentexists before accessing properties (e.g.,if (!cardRef.current) return). - This prevents 'Cannot read properties of null' errors in dynamically rendered lists.
Anti-Patterns
- Do not use
clientXandclientYfor the tilt calculation, as this causes inconsistent effects based on the card's position on the page. - Do not apply the gradient background directly to the card element itself; it must be on pseudo-elements behind the content.
- Do not forget to set
z-indexcorrectly, or the glow will cover the card content instead of framing it. - Do not omit the
overflow: hiddenon the parent, or the glow may spill outside the intended border area.
Triggers
- create a 3d tilt card effect
- add rgb glowing border to card
- implement animated gradient border
- fix card tilt logic for grid layout
- add hover glow effect to react component
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.