Create stunning, customizable snowfall animations for your ReactJS, NextJS applications with ease. Perfect for winter themes, Christmas websites, or any application that needs beautiful falling particle effects.
- ๐จ Highly Customizable: Control every aspect of the snowfall effect
- โก Performance Optimized: Smooth 60fps animations with intelligent frame timing, 50% better performance with optimized animation loop and memory management
- ๐ฑ Responsive: Automatically adapts to screen size changes with optimized resize handling
- ๐ฏ Interactive: Mouse-following snowflakes with realistic physics and enhanced mouse interaction
- ๐ผ๏ธ Custom Images: Use your own images as snowflakes with async loading - supports PNG, JPG, SVG, WebP formats, internet URLs, local files, and base64 data URIs
- ๐ญ Multiple Shapes: Built-in circle, star, and dot shapes with crisp rendering
- โ๏ธ Realistic Physics: Advanced gravity, wind, bounce, and melting effects with realistic particle behavior and collision detection
- ๐ฆ TypeScript Ready: Full TypeScript support with enhanced type definitions and improved error handling
- ๐ง Memory Efficient: Optimized resource management, automatic cleanup, and memory leak prevention
- ๐๏ธ Configurable FPS: Adaptive frame rate control for different devices
- ๐ง Smart Architecture: Modular utility functions, cleaner code organization, and reduced re-renders with React hooks optimization
This is a monorepo containing:
packages/react-snowfall-effect/- The main npm librarypackages/demo/- Next.js demo application showcasing the library
If you want to work on the library locally with the demo:
Go to the packages/demo directory:
Change dependencies to use the local library:
"@namnguyenthanhwork/react-snowfall-effect": "file:../react-snowfall-effect",
Then run (root directory):
# Install dependencies (uses npm workspaces)
npm install
# Build the library
npm run build:lib
# Run the demo in development mode
npm run dev:demoThe demo uses the local library via workspace dependencies, so changes to the library will be reflected in the demo after rebuilding.
Install the library:
npm install @namnguyenthanhwork/react-snowfall-effectUse in your React app:
import React from 'react';
import { Snowfall } from '@namnguyenthanhwork/react-snowfall-effect';
function App() {
return (
<div>
<Snowfall />
{/* Your app content */}
</div>
);
}
export default App;For detailed documentation, see packages/react-snowfall-effect/README.md.
Visit the live demo to see the library in action.
<Snowfall
snowflakeCount={100}
fps={60}
fadeEdges={true}
gravity={1}
// Optimized for smooth performance
/><Snowfall
colors={['#ffffff', '#ff6b6b', '#4ecdc4', '#ffe66d']}
snowflakeShape='star'
followMouse={true}
snowflakeCount={60}
wind={{ min: -0.8, max: 0.8 }}
accumulate={true}
// Beautiful star-shaped snowflakes with mouse interaction
/><Snowfall
images={[
'/local-snowflake.png',
'https://example.com/remote-star.svg',
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0...',
]}
snowflakeCount={40}
size={{ min: 15, max: 35 }}
// Supports PNG, JPG, SVG, WebP, URLs, and base64
/><Snowfall
snowflakeCount={30}
fps={30}
followMouse={false}
bounce={false}
// Reduced particle count and FPS for mobile devices
/>- Lightweight: < 10KB gzipped
- Smooth: 60fps animations with intelligent frame timing
- Efficient: 50% better performance with optimized rendering and memory management
- Responsive: Scales with screen size automatically with optimized resize handling
- Smart: Automatic cleanup and resource disposal
- Adaptive: Configurable FPS for different devices and performance requirements
- Desktop: 50-100 snowflakes at 60fps
- Mobile: 20-50 snowflakes at 30fps
- Low-end devices: 10-30 snowflakes at 24fps
// Responsive performance setup
<Snowfall
snowflakeCount={window.innerWidth > 768 ? 80 : 40}
fps={window.innerWidth > 768 ? 60 : 30}
followMouse={window.innerWidth > 768}
/>| Prop | Type | Default | Description |
|---|---|---|---|
snowflakeCount |
number |
50 |
Number of snowflakes (affects performance) |
images |
string[] |
[] |
Array of image URLs/paths - supports PNG, JPG, SVG, WebP, internet URLs, local files, and base64 data URIs |
speed |
{min: number, max: number} |
{min: 1, max: 3} |
Falling speed range with physics |
wind |
{min: number, max: number} |
{min: -0.5, max: 0.5} |
Horizontal wind force with realistic drift |
size |
{min: number, max: number} |
{min: 10, max: 30} |
Snowflake size range in pixels |
opacity |
{min: number, max: number} |
{min: 0.1, max: 0.8} |
Opacity range for natural variation |
rotation |
{enabled: boolean, speed: {min: number, max: number}} |
{enabled: true, speed: {min: -2, max: 2}} |
Rotation with performance optimization |
colors |
string[] |
['#ffffff'] |
Array of hex/rgb colors for snowflakes |
className |
string |
'' |
Additional CSS classes for canvas |
style |
React.CSSProperties |
{} |
Additional inline styles (memoized) |
zIndex |
number |
1000 |
Z-index of the canvas element |
fps |
number |
60 |
Target FPS with intelligent throttling |
snowflakeShape |
'circle' | 'star' | 'dot' |
'circle' |
Built-in shapes with crisp rendering |
fadeEdges |
boolean |
true |
Fade snowflakes near edges (performance optimized) |
followMouse |
boolean |
false |
Mouse interaction with realistic physics |
gravity |
number |
1 |
Gravity multiplier for natural fall |
bounce |
boolean |
false |
Realistic bouncing with damping |
melt |
boolean |
false |
Gradual melting effect near bottom |
accumulate |
boolean |
false |
Snow accumulation with collision detection |
- Chrome 60+ (Hardware acceleration recommended)
- Firefox 55+ (WebGL support recommended)
- Safari 12+ (Canvas performance optimized)
- Edge 79+ (Chromium-based)
- Best performance on devices with hardware acceleration
- Automatically adapts to device capabilities
- Graceful degradation on older browsers
- Memoized Calculations: React hooks prevent unnecessary re-computations
- Efficient Animation Loop: Intelligent frame timing with requestAnimationFrame
- Memory Management: Automatic cleanup and resource disposal
- Canvas Optimization: Optimized drawing calls and context management
import {
SnowfallProps,
Snowfall,
} from '@namnguyenthanhwork/react-snowfall-effect';
const props: SnowfallProps = {
snowflakeCount: 60,
speed: { min: 1, max: 4 },
// Full intellisense and type checking
};
<Snowfall {...props} />;- React 18+
- TypeScript
- Next.js (for demo)
- Tailwind CSS (for demo styling)
Contributions are welcome! Please see our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
MIT ยฉ Thร nh Nam Nguyแป n
Thร nh Nam Nguyแป n
- Website: https://www.thanhnamnguyen.dev/
- Email: namnguyenthanh.work@gmail.com
Give a โญ๏ธ if this project helped you!
Keywords: react, snowfall, animation, snow effect, winter animation, christmas effect, web animation, javascript, typescript, component, customizable, interactive, particles, falling animation, performance optimized, memory efficient
