
Product
Unify Your Security Stack with Socket Basics
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
@andresclua/perlindom
Advanced tools
A lightweight JavaScript library for creating smooth, organic animations for DOM elements using Perlin noise
A lightweight JavaScript library for creating smooth, organic animations on DOM elements using Perlin noise. Create natural, fluid movements that bring your web interfaces to life.
transform
and requestAnimationFrame
for smooth 60fps animationsnpm install @andresclua/perlindom
Or include directly in your HTML:
<script type="module">
import PerlinDOM from 'https://unpkg.com/@andresclua/perlindom/dist/perlindom.es.js';
</script>
import PerlinDOM from '@andresclua/perlindom';
// Basic animation - element will animate from its current position
const animation = new PerlinDOM({
element: document.querySelector('.my-element'),
x: { min: -50, max: 50 }, // Move ±50px horizontally
y: { min: -30, max: 30 }, // Move ±30px vertically
speed: 0.01, // Animation speed
seed: 123 // Reproducible pattern
});
// Control the animation
animation.pause(); // Smooth pause
animation.play(); // Resume
animation.destroy(); // Clean up
/* Your element needs positioning for transforms to work */
.my-element {
position: relative; /* or absolute, or fixed */
/* PerlinDOM will animate from wherever this element is positioned */
}
Option | Type | Default | Description |
---|---|---|---|
element | HTMLElement | required | The DOM element to animate |
x | Object | null | null | Horizontal movement: {min: number, max: number} |
y | Object | null | null | Vertical movement: {min: number, max: number} |
speed | number | 0.01 | Animation speed (lower = slower) |
seed | number | 0 | Seed for reproducible patterns |
lerpSpeed | number | 0.1 | Transition smoothness for pause/play |
{ min: -50, max: 50 }
- Fixed pixel movement{ min: '-10%', max: '10%' }
- Responsive to parent sizex: { min: '-5%', max: '5%' }, y: { min: -20, max: 20 }
null
<div class="floating-card">Content</div>
.floating-card {
position: relative;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
new PerlinDOM({
element: document.querySelector('.floating-card'),
x: { min: -20, max: 20 },
y: { min: -15, max: 15 },
speed: 0.008,
seed: 42
});
// Elements adapt to container size changes
document.querySelectorAll('.bg-particle').forEach((el, index) => {
new PerlinDOM({
element: el,
x: { min: '-15%', max: '15%' }, // 15% of parent width
y: { min: '-10%', max: '10%' }, // 10% of parent height
speed: 0.003,
seed: index * 1000
});
});
const button = document.querySelector('.animated-button');
let animation;
button.addEventListener('mouseenter', () => {
animation = new PerlinDOM({
element: button.querySelector('.effect'),
x: { min: -5, max: 5 },
y: { min: -5, max: 5 },
speed: 0.02,
lerpSpeed: 0.15
});
});
button.addEventListener('mouseleave', () => {
animation?.pause();
});
// Same seed = synchronized movement
document.querySelectorAll('.sync-element').forEach(el => {
new PerlinDOM({
element: el,
x: { min: -30, max: 30 },
y: { min: -30, max: 30 },
speed: 0.01,
seed: 12345 // Same seed for all elements
});
});
// Horizontal-only movement for sliding effects
new PerlinDOM({
element: document.querySelector('.slider'),
x: { min: -100, max: 100 },
y: null, // No vertical movement
speed: 0.005
});
// Vertical-only for floating effects
new PerlinDOM({
element: document.querySelector('.floater'),
x: null, // No horizontal movement
y: { min: -40, max: 40 },
speed: 0.008
});
// Animate SVG elements or paths
const svgElement = document.querySelector('#animated-path');
const pathAnimation = new PerlinDOM({
element: null, // No direct element
x: { min: -20, max: 20 },
y: { min: -15, max: 15 },
speed: 0.01,
seed: 999
});
function updatePath() {
const offsetX = pathAnimation.lastX;
const offsetY = pathAnimation.lastY;
// Update SVG path or transform
svgElement.style.transform = `translate(${offsetX}px, ${offsetY}px)`;
requestAnimationFrame(updatePath);
}
updatePath();
position: relative
, absolute
, or fixed
0.01
and adjust based on desired effectdestroy()
when removing elements from DOM// Good: Reuse animation instances
const sharedAnimation = new PerlinDOM({...});
// Good: Use percentage values for responsive design
x: { min: '-5%', max: '5%' }
// Good: Appropriate speeds for smooth animation
speed: 0.01 // Smooth and natural
// Good: Clean up when done
animation.destroy();
new PerlinDOM(options)
Method | Description | Returns |
---|---|---|
play() | Start or resume animation | void |
pause() | Smoothly pause animation | void |
destroy() | Stop animation and clean up resources | void |
init(seed?) | Reinitialize with optional new seed | void |
Property | Type | Description |
---|---|---|
lastX | number | Current X offset value |
lastY | number | Current Y offset value |
isPlaying | boolean | Current animation state |
speed | number | Animation speed (writable) |
lerpSpeed | number | Transition speed (writable) |
❓ Animation not visible
/* Ensure element has positioning */
.my-element {
position: relative; /* or absolute/fixed */
}
❓ Element jumps on initialization
❓ Animation too fast/slow
// Adjust speed value
speed: 0.001 // Very slow
speed: 0.01 // Normal
speed: 0.1 // Fast
❓ Percentage values not working
❓ Memory leaks
// Always clean up when removing elements
animation.destroy();
Monitor performance in DevTools:
PerlinDOM works in all modern browsers supporting:
See CHANGELOG.md for detailed version history.
MIT License - see LICENSE file for details.
Made with ❤️ by Andres Clua
PerlinDOM - Bringing organic motion to the web
FAQs
A lightweight JavaScript library for creating smooth, organic animations for DOM elements using Perlin noise
We found that @andresclua/perlindom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
Product
Socket is launching experimental protection for the Hugging Face ecosystem, scanning for malware and malicious payload injections inside model files to prevent silent AI supply chain attacks.
Research
/Security News
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.