This project creates a smooth image trail effect where images appear and follow the user's mouse cursor inside a designated container. The images fade away after a short period, creating a dynamic visual effect. The project also includes smooth scrolling using the Lenis library.
- Lenis Smooth Scrolling for a fluid page scrolling experience.
- Mouse Trail Effect with dynamically appearing images.
- Configurable Animation (duration, easing, rotation, lifespan, etc.).
- Optimized Performance using
requestAnimationFramefor smooth updates.
project-folder/
│── assets/ # Images for the trail effect
│── index.html # Main HTML file
│── styles.css # Styling for the project
│── script.js # Main JavaScript logic
│── README.md # Project documentation (this file)
This project uses Lenis for smooth scrolling.
npm install lenisAlternatively, you can include Lenis via a CDN:
<script src="https://unpkg.com/lenis@latest"></script>- Clone the repository
git clone https://github.com/your-username/trailImageEffect.git cd trailImageEffect - Install dependencies (if using npm)
npm install
- Run the project
Open
index.htmlin a browser or use Live Server in VS Code.
Modify animation settings inside script.js under the config object:
const config = {
imageCount: 35, // Number of available images
imageLifespan: 750, // Time before an image is removed (ms)
removeDelay: 50, // Delay between removing images
mouseThreshold: 100, // Minimum distance before a new image appears
inDuration: 750, // Fade-in duration
outDuration: 1000, // Fade-out duration
inEasing: "cubic-bezier(.07,.5,.5,1)",
outEasing: "cubic-bezier(.87,0,.13,1)",
};- Move your mouse inside the
.trail-containerto generate image trails. - Images will appear, rotate randomly, and disappear after a short delay.
- The effect only triggers if the mouse moves a certain distance.
The main functionality is implemented in script.js:
- Detects mouse movement inside the container.
- Generates an image at the cursor position.
- Animates the image (scaling & rotation effects).
- Removes old images after their lifespan expires.
- Uses
requestAnimationFramefor optimized performance.
UnAvailable
- Add touch support for mobile devices.
- Optimize image loading and caching.
- Allow user customization via UI controls.
Contributions are welcome! Feel free to fork the repo and submit a pull request.