Quantum Interaction Button
An advanced interactive button with quantum-inspired visual effects
Quantum Interaction Button Breakdown
🌟 Interactive Hover Effects
The button uses Framer Motion's advanced animation capabilities to create a dynamic, quantum-inspired interaction experience. As you hover over the button, multiple visual transformations occur simultaneously.
🌈 Dynamic Background Gradient
The button features a radial gradient background that dynamically follows your mouse cursor. This creates an immersive, responsive visual effect that makes the button feel alive and interactive.
✨ Quantum-Inspired Animations
- Smooth scale transformation on hover and click
- Pulsating border with infinite animation
- Glitch-like text shadow effect
🔧 Technical Highlights
Utilizes React hooks (useState) and Framer Motion's useMotionValue and useMotionTemplate for creating complex, performant animations with minimal code.
Code Breakdown and Features
0. Library Installation
# Using npm
npm install framer-motion react
# Using yarn
yarn add framer-motion react
• framer-motion
: Provides advanced animation capabilities • react
: Core React library for building the component • Ensure you're using React 16.8+ to support hooks
1. State and Motion Management
const x = useMotionValue(50);
const y = useMotionValue(50);
const [isHovered, setIsHovered] = useState(false);
• useMotionValue
creates reactive values for mouse position tracking • useState
manages hover state for dynamic animations • Initial values set to center (50%) for symmetrical starting point
2. Dynamic Background Gradient
const backgroundImage = useMotionTemplate`
radial-gradient(
300px circle at ${x}% ${y}%,
rgba(79, 70, 229, 0.2),
transparent 50%
)
`;
• Creates a radial gradient that follows mouse movement • useMotionTemplate
allows dynamic interpolation of gradient position • Provides an interactive, quantum-like visual effect
3. Mouse Movement Tracking
const handleMouseMove = (event) => {
const rect = event.target.getBoundingClientRect();
x.set((event.clientX - rect.left) / rect.width * 100);
y.set((event.clientY - rect.top) / rect.height * 100);
};
• Calculates mouse position relative to button • Converts coordinates to percentage for gradient positioning • Enables precise, responsive background tracking
4. Hover and Animation Effects
whileHover={{
scale: 1.05,
transition: {
duration: 0.3,
type: "tween"
}
}}
whileTap={{ scale: 0.98 }}
• Smooth scale transformation on hover and click • Subtle 5% size increase creates interactive feedback • Uses Framer Motion's declarative animation system