🚀 Lightweight, Fast, and Modern JavaScript Widget for Embedding Products into Any Website
This project is a fully embeddable e-commerce widget that allows you to:
- ✅ Show 5 products per viewport
- ✅ Scroll left/right with Prev/Next buttons
- ✅ Infinite looping behavior
- ✅ Fully responsive (desktop, tablet, mobile)
- ✅ Pure Vanilla JavaScript (no frameworks)
- ✅ Easily integrate into any website with one line of code
- ✅ Host the widget yourself or through a CDN
Feature | Status |
---|---|
Responsive Design | ✅ |
Horizontal Carousel with Scroll | ✅ |
5 Items Per Viewport | ✅ |
Infinite Looping | ✅ |
Lightweight & Fast | ✅ |
Shadow DOM Isolation | ✅ |
No External Dependencies | ✅ |
git clone https://github.com/your-username/your-widget-repo.git
cd your-widget-repo
npm install
npm run dev
Opens http://localhost:5173 with live reload.
npm run build
Outputs bundled
widget.min.js
todist/
npx serve .
Serves
widget.min.js
in the preview.html available here: http://localhost:3000/preview
Paste this into any HTML page:
<div id="my-ecom-widget"></div>
<script src="https://your-cdn.com/widget.min.js"></script>
<script>
window.EcomWidget.init({
selector: '#my-ecom-widget',
category: 'electronics' // optional: API category
});
</script>
✅ That's it! Your widget is now live and running inside any webpage.
Property | Type | Default | Description |
---|---|---|---|
selector |
string |
#my-ecom-widget |
CSS selector where the widget mounts |
category |
string |
'electronics' |
Fake Store API category to fetch |
visibleCount |
number |
5 |
Number of cards visible per viewport |
Example:
window.EcomWidget.init({
selector: '#your-div-id',
category: 'jewelery',
visibleCount: 5
});
-
GET products by category:
https://fakestoreapi.com/products/category/{category}
-
POST add to cart:
https://fakestoreapi.com/carts
(Free public test API — no API key required.)
- Pure Vanilla JavaScript (ES6+)
- HTML + CSS inside Shadow DOM for isolation
- Vite for development & bundling (IIFE output)
- Zero runtime dependencies
your-widget-repo/
├── widget.js # Main widget source
├── vite.config.js # Vite config for dev & build
├── package.json # npm scripts & dependencies
├── .gitignore # Ignored files (node_modules, dist, etc.)
└── dist/ # Production build output (widget.js)
.gitignore example:
node_modules/
dist/
.env
.DS_Store
.vscode/
MIT License
You are free to use, modify, distribute, and contribute!
Pull requests are very welcome!
For major changes, please open an issue first to discuss.
- Fork the repo
- Create a branch (
git checkout -b feature/...
) - Commit your changes (
git commit -m "feat: ..."
) - Push (
git push origin feature/...
) - Open a Pull Request
If you like this project, feel free to connect:
- 🐦 GitHub
- 📩 Email: oliver@akrinum.com
Made with ❤️ and JavaScript