Copy link to clipboard
Copied
Can someone tell me what I would need to change in my code (javascript) if I wanted to duplicate this slider with different images on the same page?
HTML
<div class="sketch-wrapper">
<i id="left" class="fa-solid fa-angle-left"></i>
<div class="sketch-carousel">
<img src="Images/image-1.jpg" alt="Hourglass Drawing" draggable="false">
<img src="Images/image-2.jpg" alt="Girl Drawing" draggable="false">
<img src="Images/image-3.jpg" alt="Baboon/Goriila Drawing" draggable="false">
<img src="Images/image-4.jpg" alt="Aries Merrit Drawing" draggable="false">
<img src="Images/image-5.jpg" alt="Dog Drawings" draggable="false">
<img src="Images/image-6.jpg" alt="Mom and Son Drawing" draggable="false">
<img src="Images/image-7.jpg" alt="Meditation Drawing" draggable="false">
<img src="Images/image-8.jpg" alt="Enchantress Drawing" draggable="false">
<img src="Images/image-9.jpg" alt="Muscular Man Drawing" draggable="false">
</div>
<i id="right" class="fa-solid fa-angle-right"></i>
</div>
CSS
Copy link to clipboard
Copied
You give the answer in the object of your request... So, all you have to do is duplicate the existing code.
However, you will have to just differentiate each HTML instance.
<div class="sketch-carousel" data-carousel-id="1">
Then, in order to adapt the JavaScript code, you need to mutualize the mechanism within a JavaScript function that would be common, but would identify each carousel through its identifier...
function initializeCarousel(carouselElement) {
const carousel = carouselElement.querySelector(".sketch-carousel");
const carouselId = carousel.getAttribute("data-carousel-id");
const leftButton = carouselElement.querySelector(".fa-angle-left");
const rightButton = carouselElement.querySelector(".fa-angle-right");
// all the previous code
}
So you can add as many carousels as you like, and call the function from each one of them....
const carouselElements = document.querySelectorAll(".sketch-wrapper");
carouselElements.forEach((carouselElement) => {
initializeCarousel(carouselElement);
});
To simplify the task of generating test images in within the HTML, you can use Emmet (included in DW, for example) that way instead of entering one by one your IMG, SRC, ALT... etc. for each images, you can just enter i.e :
(img[src="https://picsum.photos/640/480?random=$"][alt=""][draggable="false"])*27
and then press the TAB key.
In order not to clutter up this thread with code, I've taken the liberty of placing the whole thing online.
You'll find your original scripts at https://demo.puce-et-media.com/cambam/
and the adapted ones at https://demo.puce-et-media.com/cambam/index-2.html
Note that in the adapted part, I had to add a style to the images that have their heights hard-coded in your original CSS
Copy link to clipboard
Copied
Not an Adobe Dreamweaver question.
You should consult Sketch-Carousel documentation.
A Google search reveals these URLs:
Hope that helps.