@janmarkuslanger/floatingjs
v0.0.5
Published
Floating.js is a lightweight library for creating animated floating elements on your webpage. Perfect for festive effects like snowflakes, sparkles, or any other decorative floating items. ๐
Maintainers
Readme
Floating.js ๐
Floating.js is a lightweight library for creating animated floating elements on your webpage. Perfect for festive effects like snowflakes, sparkles, or any other decorative floating items. ๐
Features โจ
- Customizable elements: Use text, emojis, or even HTML elements.
- Control animation frequency: Adjust the number of floating elements and the interval between appearances.
- Lightweight and modular: No external dependencies.
- Easy-to-use API: Start with minimal setup.
Installation
You can include Floating.js in your project via npm:
npm install --save @janmarkuslanger/floatingjsUsage
Hereโs how to get started with Floating.js:
1. Import the Library
import { Floating } from '@janmarkuslanger/floatingjs';2. Initialize the Floating Effect
const floating = new Floating({
elements: ['โ๏ธ', 'โจ', '๐', 'โญ๏ธ'], // Elements to float (strings or custom HTML elements)
maxElements: 20, // Maximum number of floating elements (default: 10)
interval: 1000, // Interval in milliseconds between new elements (default: 2000)
});3. Start or Stop the Animation
// Start the animation
floating.start();
// Stop the animation
floating.stop();Options ๐ ๏ธ
| Option | Type | Default | Description |
|---------------|---------------------------|-------------------|-----------------------------------------------------------------------------|
| elements | string[] or Function[] | [] | Elements to float. Strings (e.g., 'โญ๏ธ') or functions returning HTML elements. |
| maxElements | number | 10 | Maximum number of floating elements visible at any time. |
| interval | number (ms) | 2000 | Interval between the creation of new floating elements (in milliseconds). |
| root | HTMLElement | document.body | The container where floating elements will be appended. |
Example ๐จ
import { Floating } from '@janmarkuslanger/floatingjs';
const snowflakes = new Floating({
elements: ['โ๏ธ', 'โ
', 'โ'], // Snowflake shapes
maxElements: 30,
interval: 500,
});
// Start the animation
snowflakes.start();
Advanced Usage ๐
const customFloating = new Floating({
elements: [
'โจ',
() => {
const customElement = document.createElement('div');
customElement.textContent = 'Custom!';
customElement.style.color = 'gold';
return customElement;
},
],
maxElements: 15,
interval: 800,
});
customFloating.start();
Contributing ๐ค
We welcome contributions! If you have suggestions, feature requests, or find a bug, please open an issue or submit a pull request.
License ๐
This project is licensed under the MIT License.
