diff --git a/Sprint-3/slideshow/index.html b/Sprint-3/slideshow/index.html index 50f2eb1c0..3df7f2fa8 100644 --- a/Sprint-3/slideshow/index.html +++ b/Sprint-3/slideshow/index.html @@ -3,12 +3,21 @@ - Title here + Image carousel + - cat-pic - - +
+

Image Carousel Demo

+ + Image carousel +
+

+ + + + + diff --git a/Sprint-3/slideshow/slideshow.js b/Sprint-3/slideshow/slideshow.js index 063ceefb5..8be4b14e3 100644 --- a/Sprint-3/slideshow/slideshow.js +++ b/Sprint-3/slideshow/slideshow.js @@ -3,6 +3,65 @@ const images = [ "./assets/cute-cat-b.jpg", "./assets/cute-cat-c.jpg", ]; +// Write your code here +let currentIndex = 0; +let intervalId = null; -// Write your code here \ No newline at end of file +const indexDisplay = document.getElementById("image-index"); +const imageElement = document.getElementById("carousel-image"); + +function updateImage() { + imageElement.src = images[currentIndex]; + indexDisplay.textContent = `${currentIndex + 1} `; +} + +function nextImage() { + currentIndex = (currentIndex + 1) % images.length; + updateImage(); +} + +function previousImage() { + currentIndex = (currentIndex - 1 + images.length) % images.length; + updateImage(); +} + +function AutoPlay(direction) { + stopAutoPlay(); + + intervalId = setInterval(function () { + if (direction === "forward") { + nextImage(); + } else { + previousImage(); + } + }, 1000); // Every 1 seconds +} + +function stopAutoPlay() { + clearInterval(intervalId); + + currentIndex = 0; // Reset index + updateImage(); +} + +document.getElementById("auto-back").addEventListener("click", function () { + AutoPlay("back"); +}); + +document.getElementById("back").addEventListener("click", function () { + previousImage(); +}); + +document.getElementById("forward").addEventListener("click", function () { + nextImage(); +}); + +document.getElementById("auto-forward").addEventListener("click", function () { + AutoPlay("forward"); +}); + +document.getElementById("stop").addEventListener("click", stopAutoPlay); + + +updateImage(); diff --git a/Sprint-3/slideshow/style.css b/Sprint-3/slideshow/style.css index 63cedf2d2..a9eb7e43e 100644 --- a/Sprint-3/slideshow/style.css +++ b/Sprint-3/slideshow/style.css @@ -1 +1,50 @@ -/** Write your CSS in here **/ +/** Writ/* Reset default styles */ +* { + box-sizing: border-box; + margin: 0; + padding: 0; +} + +body { + font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; + background-color: #f4f4f4; + text-align: center; + padding: 2rem; +} + +#carousel-image { + max-width: 50%; + max-height: 50%; + border-radius: 10px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); + margin-bottom: 1.rem; + margin-top: 2rem; + transition: opacity 0.3s ease-in-out; +} + +button { + background-color: #007acc; + color: white; + border: none; + padding: 0.6rem 1.2rem; + font-size: 1rem; + border-radius: 4px; + cursor: pointer; + transition: background-color 0.3s ease; +} + +.image-index { + font-size: 1.2rem; + margin-left: 1rem; + text-align: left; + color: #333; +} + +button:hover { + background-color: #005fa3; +} + +button:active { + transform: scale(0.97); +} +