-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (30 loc) · 1.06 KB
/
Copy pathscript.js
File metadata and controls
36 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
document.addEventListener("DOMContentLoaded", function() {
const sliderContainer = document.querySelector('.shapesss');
const shapes = document.querySelectorAll('.shape');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
let currentIndex = 0;
const shapeWidth = shapes[0].offsetWidth;
const totalShapes = shapes.length;
function moveShapes(direction) {
if (direction === 'next') {
currentIndex++;
if (currentIndex >= totalShapes) {
currentIndex = 0;
}
} else if (direction === 'prev') {
currentIndex--;
if (currentIndex < 0) {
currentIndex = totalShapes - 1;
}
}
const displacement = currentIndex * -shapeWidth;
sliderContainer.style.transform = `translateX(${displacement}px)`;
}
prevBtn.addEventListener('click', () => {
moveShapes('prev');
});
nextBtn.addEventListener('click', () => {
moveShapes('next');
});
});