A JavaScript package for creating beautiful, animated backgrounds 📦
The Scape.js is a lightweight JavaScript package that allows you to create beautiful, animated backgrounds for your website. Whether you want floating shapes or custom images, this package has you covered.
All API methods must be wrapped in a DOMContentLoaded event listener to ensure proper functionality:
document.addEventListener('DOMContentLoaded', () => {
// Your Scape.js code here
});
<script src="https://cdn.jsdelivr.net/gh/Ali-Cheikh/scape.js@main/scape.js"></script>
window.ScapeConfig = {
type: 'shape',
shape: 'star',
count: 30
};
window.ScapeConfig = {
type: 'image',
imageUrl: 'path/to/image.png',
count: 20
};
Option | Type | Default | Description |
---|---|---|---|
type | string | 'shape' | 'shape' or 'image' |
imageUrl | string | githubImg | URL for image elements |
shape | string | 'heart' | Shape type (see Shape Types) |
count | number | 30 | Number of elements |
size | number | 50 | Size in pixels |
spacing | number | 200 | Space between elements |
minDistance | number | 150 | Minimum element distance |
animationDuration | string | '3s' | Animation duration |
floatDistance | number | 30 | Float animation distance |
rotationRange | number | 360 | Maximum rotation degrees |
hoverScale | number | 1.1 | Scale factor on hover |
opacity | number | 0.8 | Base opacity |
fillColor | string | 'hsla(200, 90%, 60%, 0.8)' | Shape fill color |
strokeColor | string | 'rgba(255, 255, 255, 0.5)' | Shape stroke color |
strokeWidth | number | 2 | Shape stroke width |
onClick | function | null | Click event callback |
onHover | function | null | Hover event callback |
// Refresh the background
ScapeJs.refresh();
// Update configuration
ScapeJs.updateConfig({
shape: 'heart',
count: 50
});
// Remove all elements
ScapeJs.destroy();
// Change image source
ScapeJs.setImage('path/to/new-image.png');
// Change shape type
ScapeJs.setShape('star');
// Animation control
ScapeJs.pause();
ScapeJs.resume();
circle
hexagon
triangle
pentagon
diamond
heart
star
fly
flower
spiral
splash
tesseract
boom
wave
clover
ripple
shell
fractal
snowflake
window.ScapeConfig = {
// ...other options
onClick: (event) => {
const element = event.target;
// Handle click
},
onHover: (event) => {
const element = event.target;
// Handle hover
}
};
document.addEventListener('DOMContentLoaded', () => {
window.ScapeConfig = {
type: 'shape',
shape: 'heart',
count: 15,
hoverScale: 1.2,
onClick: (e) => {
e.target.style.fillColor = 'red';
}
};
});
-
Element Count
- Mobile: 10-20 elements
- Desktop: 20-40 elements
- High-performance: up to 100 elements
-
Animation Performance
- Use simpler shapes for better performance
- Reduce floatDistance on mobile
- Consider disabling rotation on low-end devices
-
Memory Management
- Always use
Scape.destroy()
before page unload - Clean up event listeners when removing elements
- Use appropriate spacing values
- Always use
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Partial support for IE11
If elements don't appear:
- Check console for errors
- Verify DOM is loaded
- Check z-index conflicts
- Verify shape type is valid
- Check image URLs for image type
- v1.0.1: Added new shapes, improved performance
- v1.0.0: Initial release For detailed configuration options, see the documentation.