0% found this document useful (0 votes)
10 views1 page

JavaScript Carousel Slider Functionality

The document contains JavaScript code for a carousel component that allows users to navigate through items using 'next' and 'prev' buttons. It automatically advances to the next item after a specified interval and updates the display accordingly. The code manages the DOM elements related to the carousel and handles the transitions between items.

Uploaded by

Nemesis
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

JavaScript Carousel Slider Functionality

The document contains JavaScript code for a carousel component that allows users to navigate through items using 'next' and 'prev' buttons. It automatically advances to the next item after a specified interval and updates the display accordingly. The code manages the DOM elements related to the carousel and handles the transitions between items.

Uploaded by

Nemesis
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//step 1: get DOM

let nextDom = [Link]('next');


let prevDom = [Link]('prev');

let carouselDom = [Link]('.carousel');


let SliderDom = [Link]('.carousel .list');
let thumbnailBorderDom = [Link]('.carousel .thumbnail');
let thumbnailItemsDom = [Link]('.item');
let timeDom = [Link]('.carousel .time');

[Link](thumbnailItemsDom[0]);
let timeRunning = 3000;
let timeAutoNext = 7000;

[Link] = function(){
showSlider('next');
}

[Link] = function(){
showSlider('prev');
}
let runTimeOut;
let runNextAuto = setTimeout(() => {
[Link]();
}, timeAutoNext)
function showSlider(type){
let SliderItemsDom = [Link]('.carousel .list .item');
let thumbnailItemsDom =
[Link]('.carousel .thumbnail .item');

if(type === 'next'){


[Link](SliderItemsDom[0]);
[Link](thumbnailItemsDom[0]);
[Link]('next');
}else{
[Link](SliderItemsDom[[Link] - 1]);
[Link](thumbnailItemsDom[[Link] -
1]);
[Link]('prev');
}
clearTimeout(runTimeOut);
runTimeOut = setTimeout(() => {
[Link]('next');
[Link]('prev');
}, timeRunning);

clearTimeout(runNextAuto);
runNextAuto = setTimeout(() => {
[Link]();
}, timeAutoNext)
}

You might also like