senangwebs-loading
v1.2.5
Published
Lightweight JavaScript library that provides customizable loading screens for web applications.
Maintainers
Readme
SenangWebs Loading (SWL)
SenangWebs Loading (SWL) is a lightweight JavaScript library that provides customizable loading screens for web applications. With minimal setup, you can add elegant loading animations to your web pages, enhancing the user experience during page load.
Features
- Instant loading indicator before DOM loads
- Easy to integrate with existing projects
- Multiple loader types: spinner, pulsing, and custom image
- Customizable colors for loaders and overlay
- Configurable overlay stacking level
- Backdrop blur effect option
- Minimum duration setting to ensure visibility of the loading screen
- Priority loading - shows immediately before page content
- Smooth fade-out transitions
- Image preloading support
- No dependencies, pure vanilla JavaScript
- Compatible with Tailwind CSS
- Responsive and works on all modern browsers
Examples
https://unpkg.com/senangwebs-loading@latest/examples/index.html
Installation
Using npm
npm install senangwebs-loadingUsing a CDN
Include SenangWebs Loading in your HTML file's head section with the defer attribute:
<head>
<script src="https://unpkg.com/senangwebs-loading@latest/dist/swl.js" defer></script>
</head>Usage
- Include the SWL JavaScript file in your HTML's head section with defer:
<!-- If installed via npm -->
<head>
<script src="path/to/swl.js" defer></script>
</head>
<!-- Or if using unpkg -->
<head>
<script src="https://unpkg.com/senangwebs-loading@latest/dist/swl.js" defer></script>
</head>- Add a div element with the
data-swlattribute and any customization options:
<div
data-swl
data-swl-type="spinner"
data-swl-color="#007bff"
data-swl-duration="2000"
data-swl-bg-color="#ffffff"
data-swl-bg-opacity="0.8"
data-swl-bg-blur="5"
data-swl-z-index="9999"
>
<!-- Optional: Custom loader content -->
</div>Configuration Options
You can customize the loader using the following data attributes:
| Attribute | Default | Description |
|---|---:|---|
| data-swl-type | spinner | Loader type: spinner, pulse, or image |
| data-swl-color | #000000 | Spinner or pulse color |
| data-swl-image | none | URL for the custom image loader |
| data-swl-duration | 0 | Minimum display duration in milliseconds |
| data-swl-bg-color | #ffffff | Overlay background color |
| data-swl-bg-opacity | 0.8 | Overlay background opacity |
| data-swl-bg-blur | 0 | Backdrop blur in pixels |
| data-swl-z-index | 9999 | Overlay stacking level; the configured value overrides the default |
Performance Best Practices
- Place the script in the head with defer attribute:
<head>
<script src="path/to/swl.js" defer></script>
</head>- Preload custom loader images:
<head>
<link rel="preload" href="path/to/loader.gif" as="image">
</head>- Use appropriate minimum duration:
- For small pages: 500-1000ms
- For medium pages: 1000-2000ms
- For content-heavy pages: 2000-3000ms
- Choose a z-index that matches your application:
- The default is
9999 - Use a higher value when the loader must appear above application modals
- Use a lower value when selected application UI should remain visible
Examples
Default Spinner
<div data-swl data-swl-color="#007bff" data-swl-duration="2000"></div>Pulsing Loader with Custom Color
<div data-swl data-swl-type="pulse" data-swl-color="#ff0000" data-swl-duration="3000"></div>Custom Image Loader
<div data-swl data-swl-type="image" data-swl-image="/path/to/your/loader.gif" data-swl-duration="2500"></div>Customized Overlay
<div
data-swl
data-swl-type="spinner"
data-swl-color="#00ff00"
data-swl-duration="3000"
data-swl-bg-color="#000000"
data-swl-bg-opacity="0.5"
data-swl-bg-blur="5"
data-swl-z-index="10000">
</div>Custom Loader Content
<div data-swl data-swl-duration="2000">
<div class="custom-loader">Loading...</div>
</div>Browser Support
SenangWebs Loading works on all modern browsers, including:
- Chrome
- Firefox
- Safari
- Edge
- Opera
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Acknowledgments
- Inspired by various loading screen libraries in the web development community
- Thanks to all contributors who have helped to improve this library
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.
