
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@pd200x/custom-image-carousel
Advanced tools
A lightweight, easy-to-use image carousel component with navigation dots, arrow controls, and smooth scrolling. Perfect for showcasing images in a clean, responsive interface.
Live Demo - See the component in action!
First, install the package in your project:
npm install @pd200x/custom-image-carousel
If you're not using npm, you can manually download and include these two essential files:
custom-image-carousel.js
- The main component JavaScript filecomponent.css
- The required CSS stylesYou can find these files:
src/js/components/custom-image-carousel.js
src/css/component.css
Then include them in your HTML:
<link rel="stylesheet" href="path/to/component.css" />
<script src="path/to/custom-image-carousel.js"></script>
<div id="my-carousel" style="height: 400px;"></div>
// Import the component
import { CustomImageCarousel, ImageItem } from "@pd200x/custom-image-carousel";
// Create an array of image items
const imageItems = [
new ImageItem({ src: "path/to/image1.jpg" }),
new ImageItem({
src: "path/to/image2.jpg",
link: "https://example.com",
mode: "_blank",
}),
new ImageItem({ src: "path/to/image3.jpg", link: "https://anothersite.com" }),
];
// Create and initialize the carousel
const carousel = new CustomImageCarousel({
containerID: "my-carousel", // ID of your container from Step 1
imageItemArray: imageItems, // Image items from above
});
// IMPORTANT: Always call initialise() to set up the carousel
carousel.initialise();
That's it! Your image carousel is ready to use.
You can easily change how the carousel looks by targeting these CSS classes:
.mcic-container
- The entire carousel container.mcic-image-group
- The scrollable area containing images.mcic-image-container
- Individual image containers.mcic-navigation-dots-container
- Container for navigation dots.mcic-navigation-dot
- Individual navigation dots.mcic-navigation-dot-selected
- The currently selected dot.mcic-left-arrow-button
- Left navigation arrow.mcic-right-arrow-button
- Right navigation arrow/* Make the carousel container more stylish */
.mcic-container {
border-radius: 12px !important;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
}
/* Style the navigation dots */
.mcic-navigation-dot {
height: 12px !important;
width: 12px !important;
background-color: #e0e0e0 !important;
}
/* Style the selected dot */
.mcic-navigation-dot-selected {
background-color: #4a5568 !important;
transform: scale(1.2) !important;
}
/* Style the navigation arrows */
.mcic-left-arrow-button,
.mcic-right-arrow-button {
background-color: rgba(255, 255, 255, 0.8) !important;
border-radius: 50% !important;
padding: 10px !important;
}
You may need to use !important
in your CSS rules when customizing the component styles if your own CSS specificity is not high enough to override the component's built-in styles.
initialise()
After creating your carousel, you must call the initialise()
method to make it work:
// Create your carousel
const carousel = new CustomImageCarousel({
// ...your options here
});
// ALWAYS do this or your carousel won't work!
carousel.initialise();
This step is essential because it:
Option | Type | Required | Description |
---|---|---|---|
containerID | string | Yes | ID of the HTML element that will contain the carousel |
imageItemArray | ImageItem[] | Yes | Array of images to display in the carousel |
Option | Type | Required | Description |
---|---|---|---|
src | string | Yes | Path or URL to the image |
link | string | No | URL to navigate to when the image is clicked |
mode | string | No | Target for link: "_blank" (new tab) or "_self" (same tab). Default is "_self" |
Method | Description |
---|---|
initialise() | Required: Sets up the carousel and returns the carousel instance |
displayItemNumber(itemNumber) | Navigates to a specific item (1-based index) |
setCycle(delay) | Enables auto-cycling with the specified delay (seconds) |
stopCycle() | Stops auto-cycling behavior |
import { CustomImageCarousel, ImageItem } from "@pd200x/custom-image-carousel";
// Create and initialize a product gallery
const productGallery = new CustomImageCarousel({
containerID: "product-gallery",
imageItemArray: [
new ImageItem({
src: "product-front.jpg",
link: "https://store.com/product-details",
}),
new ImageItem({ src: "product-back.jpg" }),
new ImageItem({ src: "product-side.jpg" }),
new ImageItem({
src: "product-detail.jpg",
link: "https://store.com/size-guide",
mode: "_blank",
}),
],
}).initialise();
// Create and initialize the carousel
const carousel = new CustomImageCarousel({
containerID: "image-carousel",
imageItemArray: [
new ImageItem({ src: "image1.jpg" }),
new ImageItem({ src: "image2.jpg" }),
new ImageItem({ src: "image3.jpg" }),
new ImageItem({ src: "image4.jpg" }),
new ImageItem({ src: "image5.jpg" }),
],
}).initialise();
// Navigate to the third image (index is 1-based)
carousel.displayItemNumber(3);
// Create and initialize a carousel with auto-cycling
const autoCyclingCarousel = new CustomImageCarousel({
containerID: "auto-carousel",
imageItemArray: [
new ImageItem({ src: "slide1.jpg", link: "https://example.com/page1" }),
new ImageItem({
src: "slide2.jpg",
link: "https://example.com/page2",
mode: "_blank",
}),
new ImageItem({ src: "slide3.jpg" }),
],
}).initialise();
// Set up auto-cycling with 2 second delay
autoCyclingCarousel.setCycle(2);
Works in all modern browsers including:
For optimal performance, consider these tips:
ISC © Pritam Debnath
FAQs
Custom-made Image Carousel UI Component.
We found that @pd200x/custom-image-carousel demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.