-
-
Notifications
You must be signed in to change notification settings - Fork 194
West Midlands | 25-ITP-Sep | Baba Yusuf | Sprint 3 | Slideshow #907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
11e30f5
3cb29a0
3d4c407
17dea8e
805fee7
532d29e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,61 @@ | ||
| const images = [ | ||
| "./assets/cute-cat-a.png", | ||
| "./assets/cute-cat-b.jpg", | ||
| "./assets/cute-cat-c.jpg", | ||
| "./assets/cute-cat-a.png", | ||
| "./assets/cute-cat-b.jpg", | ||
| "./assets/cute-cat-c.jpg", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of array to store image paths. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add one more image path to the images array. |
||
| ]; | ||
|
|
||
| //Write your code here | ||
| let currentIndex = 0; | ||
| let intervalId = null; | ||
|
|
||
| // Write your code here | ||
| const imgElement = document.getElementById("carousel-img"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct DOM selection |
||
| const forwardBtn = document.getElementById("forward-btn"); | ||
| const backwardBtn = document.getElementById("backward-btn"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear variable names |
||
|
|
||
| const autoForwardBtn = document.getElementById("auto-forward"); | ||
| const autoBackwardBtn = document.getElementById("auto-backward"); | ||
| const stopBtn = document.getElementById("stop"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of const because they don’t change |
||
|
|
||
| function updateImage() { | ||
| imgElement.src = images[currentIndex]; | ||
| } | ||
|
|
||
| function moveForward() { | ||
| currentIndex = (currentIndex + 1) % images.length; | ||
| updateImage(); | ||
| } | ||
|
|
||
| function moveBackward() { | ||
| currentIndex = (currentIndex - 1 + images.length) % images.length; | ||
| updateImage(); | ||
| } | ||
|
|
||
| forwardBtn.addEventListener("click", moveForward); | ||
| backwardBtn.addEventListener("click", moveBackward); | ||
|
|
||
| // ---- AUTOMATIC SLIDESHOW ---- | ||
|
|
||
| function startAuto(direction) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥very good job wiith this function |
||
| stopAuto(); // clear any previous interval | ||
|
|
||
| // Disable auto buttons | ||
| autoForwardBtn.disabled = true; | ||
| autoBackwardBtn.disabled = true; | ||
|
|
||
| intervalId = setInterval(() => { | ||
| direction === "forward" ? moveForward() : moveBackward(); | ||
| }, 2000); | ||
| } | ||
|
|
||
| function stopAuto() { | ||
| clearInterval(intervalId); | ||
| intervalId = null; | ||
|
|
||
| // Re-enable buttons | ||
| autoForwardBtn.disabled = false; | ||
| autoBackwardBtn.disabled = false; | ||
| } | ||
|
|
||
| autoForwardBtn.addEventListener("click", () => startAuto("forward")); | ||
| autoBackwardBtn.addEventListener("click", () => startAuto("backward")); | ||
| stopBtn.addEventListener("click", stopAuto); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! @Baba05206