Florin Pop’s mini project no. 10
What’s interesting
- Florin used an image container inside the carousel and then used
transform: translateX
on that single element moving all the images together as a block, rather than each image like I did before. - Using
images.length
to count the number of images and use that to determine the amount intranslateX(distance)
ToDo’s
- Make responsive
- inside a modal?
- Add an image button which creates a new image element with the url.
- auto play / stop
- Use alt tag to display a title.
Previous attempt on JS Fiddle.
const imgCont = document.getElementById('imgContainer');
const nextBtn = document.getElementById('nextBtn');
const images = document.querySelectorAll('#imgContainer img');
nextBtn.addEventListener('click', () => {
changeImg();
})
let i = 1;
function changeImg() {
if (i >= images.length) {
i = 0;
}
let distance = 600 * -i;
imgCont.style.transform = `translateX(${distance}px)`;
i++;
console.log('i = ' + i + ' distance = ' + distance);
}