Creating a Valentine's Day Special Page with Next.js and Framer Motion
Published on
/10 mins read/---
Creating a Valentine's Day Special Page with Next.js and Framer Motion
In this blog post, I'll share how I created a special Valentine's Day page using Next.js, Framer Motion, and TypeScript. The page features beautiful animations, an interactive mini-game, and a gift redemption system. Let's dive into the technical implementation details and explore how to create engaging web experiences.
Project Overview
The Valentine's Day special page consists of three main components:
An animated love letter with smooth transitions and heartbeat effects
A mobile-friendly space shooter mini-game
A gift code redemption system with conditional rendering
Let's explore each component and see how they work together.
The Animated Love Letter
The love letter section uses Framer Motion for smooth animations. Here's how we implemented the fade-in and heartbeat animations:
These animations create a welcoming and dynamic feel as users first load the page. The love letter content is wrapped in motion components that use these animations:
<motion.div variants={fadeInUp} className="prose max-w-none dark:prose-invert"> <p className="text-lg text-gray-700 dark:text-gray-100 md:text-xl">Dear Wenlin,</p> <p className="text-lg text-gray-700 dark:text-gray-100 md:text-xl"> Every moment with you is a gift that I cherish deeply... </p></motion.div>
The Space Shooter Mini-game
The mini-game is built entirely with React hooks and declarative rendering, making it lightweight and performant. Using React's state management and refs, we achieved smooth gameplay while maintaining code maintainability. It features responsive design and works seamlessly on both desktop and mobile devices.
Key features include:
Responsive game area that adapts to screen size
Dual control system: keyboard (arrow keys/WASD) and touch controls
Auto-firing bullet system
Heart collection with collision detection
Score tracking and countdown timer
Win condition: collect 10 hearts within 20 seconds
Performance Optimization: Used React refs and requestAnimationFrame for smooth gameplay:
useEffect(() => { let animationFrameId: number const update = (timestamp: number) => { // Game logic update animationFrameId = requestAnimationFrame(update) } animationFrameId = requestAnimationFrame(update) return () => cancelAnimationFrame(animationFrameId)}, [])
Conclusion
Creating this Valentine's Day special page was an exciting project that combines modern web technologies with interactive elements. The combination of Next.js, Framer Motion, and TypeScript provided a solid foundation for building an engaging user experience that works well across all devices.
The source code is available on GitHub, feel free to use it as inspiration for your own special occasion pages!
<motion.div variants={fadeInUp} className="prose max-w-none dark:prose-invert"> <p className="text-lg text-gray-700 dark:text-gray-100 md:text-xl">Dear Wenlin,</p> <p className="text-lg text-gray-700 dark:text-gray-100 md:text-xl"> Every moment with you is a gift that I cherish deeply... </p></motion.div>
Performance Optimization: Used React refs and requestAnimationFrame for smooth gameplay:
useEffect(() => { let animationFrameId: number const update = (timestamp: number) => { // Game logic update animationFrameId = requestAnimationFrame(update) } animationFrameId = requestAnimationFrame(update) return () => cancelAnimationFrame(animationFrameId)}, [])
Conclusion
Creating this Valentine's Day special page was an exciting project that combines modern web technologies with interactive elements. The combination of Next.js, Framer Motion, and TypeScript provided a solid foundation for building an engaging user experience that works well across all devices.
The source code is available on GitHub, feel free to use it as inspiration for your own special occasion pages!