Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions Sprint-3/slideshow/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<script defer src="slideshow.js"></script>
</head>
<body>
<img id="carousel-img" src="./assets/cute-cat-a.png" alt="cat-pic" />
<button type="button" id="backward-btn">Backwards</button>
<button type="button" id="forward-btn">Forward</button>
</body>
</html>
body {
background-color: rgb(242, 106, 106);
}

#carousel-img {
width: 745px;
height: 559px;
object-fit: cover;
display: block;
margin: 0 auto;
border-radius: 8px; /* minor visual improvement */
}

#button-container {
display: flex;
justify-content: center;
gap: 12px; /* slightly smoother spacing */
margin-top: 20px;
}

.button {
background-color: bisque;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
font-size: 16px; /* fixing invalid font-size line */
font-style: oblique;
border-radius: 8px;
padding: 10px 24px;
cursor: pointer;
border: none; /* minor improvement */
transition: transform 0.2s ease; /* subtle UX enhancement */
}

.button:hover {
transform: scale(1.05);
}
67 changes: 65 additions & 2 deletions Sprint-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,71 @@
const images = [
window.images = [
"./assets/cute-cat-a.png",
"./assets/cute-cat-b.jpg",
"./assets/cute-cat-c.jpg",
];

let currentIndex = 0;
let intervalId = null;

// Write your code here
// Moves carousel one step (forward or backward)
function moveFrontOnce(forward) {
const images = window.images;

currentIndex = forward
? (currentIndex + 1) % images.length
: (currentIndex - 1 + images.length) % images.length;

const image = document.getElementById("carousel-img");
if (image) image.src = images[currentIndex]; // cleaner + safer
}

// Starts automatic forward movement
function startAutoForward() {
stopAuto();
intervalId = setInterval(() => moveFrontOnce(true), 2000);
toggleButtons(true);
}

// Starts automatic backward movement
function startAutoBackward() {
stopAuto();
intervalId = setInterval(() => moveFrontOnce(false), 2000);
toggleButtons(true);
}

// Stops any active autoplay
function stopAuto() {
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
toggleButtons(false);
}

// Enables/disables control buttons
function toggleButtons(isRunning) {
document.getElementById("auto-forward").disabled = isRunning;
document.getElementById("auto-backward").disabled = isRunning;
document.getElementById("stop").disabled = !isRunning;
}

// Register button click handlers
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("forward-btn")
.addEventListener("click", () => moveFrontOnce(true));

document.getElementById("backward-btn")
.addEventListener("click", () => moveFrontOnce(false));

document.getElementById("auto-forward")
.addEventListener("click", startAutoForward);

document.getElementById("auto-backward")
.addEventListener("click", startAutoBackward);

document.getElementById("stop")
.addEventListener("click", stopAuto);

// Stop is disabled initially
document.getElementById("stop").disabled = true;
});
36 changes: 36 additions & 0 deletions Sprint-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
/** Write your CSS in here **/
body {
background-color: rgb(242, 106, 106);
}

#carousel-img {
width: 745px;
height: 559px;
object-fit: cover;
display: block;
margin: 0 auto;
border-radius: 8px; /* minor visual improvement */
}

#button-container {
display: flex;
justify-content: center;
gap: 12px; /* slightly smoother spacing */
margin-top: 20px;
}

.button {
background-color: bisque;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
font-size: 16px; /* fixing invalid font-size line */
font-style: oblique;
border-radius: 8px;
padding: 10px 24px;
cursor: pointer;
border: none; /* minor improvement */
transition: transform 0.2s ease; /* subtle UX enhancement */
}

.button:hover {
transform: scale(1.05);
}