What Is This?
Scape.js is a lightweight (~5KB) JavaScript package that creates beautiful, animated backgrounds for your website. Whether you want floating shapes, custom images, or interactive elements, this package has you covered.
- 18+ unique shapes (stars, hearts, fractals and more)
- Custom image support
- Fully configurable animation and appearance
- Interactive elements with hover/click events
How It Works
The package dynamically generates shapes or images and animates them across the screen. You can customize the type, size, color, and animation of the elements.
            
// Example Configuration
window.ScapeConfig = {
  type: 'shape', // 'image' or 'shape'
  shape: 'star', // Shape type
  count: 30, // Number of elements
  size: 10, // Size of each element
  fillColor: 'hsla(200, 90%, 60%, 0.8)', // Fill color
  strokeColor: 'rgba(255, 255, 255, 0.5)', // Stroke color
  strokeWidth: 2, // Stroke width
};
            
          
          
        How to Implement
Follow these steps to add the Scape.js to your website:
- 
            Include the script in your HTML file:
            <script src="https://cdn.jsdelivr.net/gh/Ali-Cheikh/scape.js@main/scape.js"></script> <script src="config.js"></script>
- 
            Create a config.jsfile to customize the background:window.ScapeConfig = { type: 'shape', shape: 'star', count: 30, size: 100, fillColor: 'hsla(200, 90%, 60%, 0.8)', strokeColor: 'rgba(255, 255, 255, 0.5)', strokeWidth: 2, };
- 
            For image-based backgrounds, use this configuration:
            window.ScapeConfig = { type: 'image', imageUrl: 'path/to/your/image.png', count: 20, size: 50, spacing: 100, minDistance: 30, animationDuration: '3s', floatDistance: 20, rotationRange: 45, opacity: 0.8 };
API Documentation
Control your background dynamically with these methods:
| Method | Description | Example | 
|---|---|---|
| refresh() | Regenerates the background | Scape.refresh() | 
| updateConfig() | Updates configuration | Scape.updateConfig({ shape: 'heart' }) | 
| destroy() | Removes all elements | Scape.destroy() | 
| setImage() | Sets new image URL | Scape.setImage('logo.png') | 
| pause() | Pauses animations | Scape.pause() | 
| resume() | Resumes animations | Scape.resume() | 
Important Note All API methods should be called after the DOM is fully loaded. Wrap your code in an event listener:
            
document.addEventListener('event/action', () => { 
  // Your Scape.js code here e.g. Scape.refresh() etc
});
             
          
        ⚠️ Be cautious when using the destroy() method instead of document.add.. use window.add..
