generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 211
ZA | 25-ITP-May | Malusi Skunyana | Sprint 3 | Slideshow #761
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
28637c8
update slideshow.test.js to access puppy images
MalusiS b6d1455
Add images directory (puppy images) and .gitignore for Sprint-3
MalusiS b47fe62
updated image file path
MalusiS 0cf79ec
Update index.html with grouped button rows, linked style.css, and imp…
MalusiS 1a17d55
Implement image carousel functionality with manual and auto navigatio…
MalusiS e6bdac8
Add styling for centered image, evenly spaced button rows, and hover/…
MalusiS 8e22b9b
Fix: stop auto-advance when forward or backward button is clicked
MalusiS 2b74dd7
Test: add test to verify that manual navigation stops auto-advance mode
MalusiS 1787b3a
Enhance: group all manual and auto slideshow buttons in a single sema…
MalusiS 50b9bad
Style: add spacing between manual and auto button rows for better lay…
MalusiS b1c77d1
Fix: update carousel image src to './images/puppy1.jpg' to pass Jest …
MalusiS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| *.docx | ||
| prep/ | ||
| package-lock.json | ||
| ../package-lock.json | ||
| ../../Sprint-1/package-lock.json | ||
| ../../Sprint-2/package-lock.json | ||
| ../alarmclock/package.json |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,26 @@ | ||
| <!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> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Image carousel</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| <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> | ||
| <h1>Image Carousel</h1> | ||
|
|
||
| <img id="carousel-img" src="./images/puppy1.jpg" alt="puppy-pic" /> | ||
|
|
||
| <div class="button-row"> | ||
| <button id="backward-btn">Backwards</button> | ||
| <button id="forward-btn">Forward</button> | ||
| </div> | ||
|
|
||
| <div class="button-row"> | ||
| <button id="auto-backward">Auto Backwards</button> | ||
| <button id="auto-forward">Auto Forward</button> | ||
| <button id="stop">Stop</button> | ||
| </div> | ||
| </body> | ||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,56 @@ | ||
| const images = [ | ||
| "./assets/cute-cat-a.png", | ||
| "./assets/cute-cat-b.jpg", | ||
| "./assets/cute-cat-c.jpg", | ||
| "./images/puppy1.jpg", | ||
| "./images/puppy2.jpg", | ||
| "./images/puppy3.jpg", | ||
| "./images/puppy4.jpg", | ||
| ]; | ||
|
|
||
| let currentIndex = 0; | ||
| let intervalId = null; | ||
| const intervalTime = 2000; // 2 seconds | ||
|
|
||
| // Write your code here | ||
| // Get DOM elements | ||
| const carouselImg = document.getElementById("carousel-img"); | ||
| const forwardBtn = document.getElementById("forward-btn"); | ||
| const backwardBtn = document.getElementById("backward-btn"); | ||
| const autoForwardBtn = document.getElementById("auto-forward"); | ||
| const autoBackwardBtn = document.getElementById("auto-backward"); | ||
| const stopBtn = document.getElementById("stop"); | ||
|
|
||
| // Manual navigation | ||
| function showImage(index) { | ||
| carouselImg.src = images[index]; | ||
| } | ||
|
|
||
| function nextImage() { | ||
| currentIndex = (currentIndex + 1) % images.length; | ||
| showImage(currentIndex); | ||
| } | ||
|
|
||
| function prevImage() { | ||
| currentIndex = (currentIndex - 1 + images.length) % images.length; | ||
| showImage(currentIndex); | ||
| } | ||
|
|
||
| forwardBtn.addEventListener("click", nextImage); | ||
| backwardBtn.addEventListener("click", prevImage); | ||
|
|
||
| // Auto navigation | ||
| function startAuto(directionFn) { | ||
| // Disable auto buttons while running | ||
| autoForwardBtn.disabled = true; | ||
| autoBackwardBtn.disabled = true; | ||
|
|
||
| intervalId = setInterval(directionFn, intervalTime); | ||
| } | ||
|
|
||
| function stopAuto() { | ||
| clearInterval(intervalId); | ||
| intervalId = null; | ||
| autoForwardBtn.disabled = false; | ||
| autoBackwardBtn.disabled = false; | ||
| } | ||
|
|
||
| autoForwardBtn.addEventListener("click", () => startAuto(nextImage)); | ||
| autoBackwardBtn.addEventListener("click", () => startAuto(prevImage)); | ||
| stopBtn.addEventListener("click", stopAuto); | ||
|
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 job separating concerns! The individual functions make the code more readable.
Author
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. I appreciate all the great feedback you have given. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,46 @@ | ||
| /** Write your CSS in here **/ | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| background-color: #f4f4f4; | ||
| margin: 0; | ||
| padding: 20px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| h1 { | ||
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| #carousel-img { | ||
| width: 400px; | ||
| max-width: 100%; | ||
| border-radius: 8px; | ||
| box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); | ||
| margin-bottom: 15px; | ||
| } | ||
|
|
||
| .button-row { | ||
| display: flex; | ||
| justify-content: center; | ||
| gap: 10px; | ||
| margin-bottom: 10px; | ||
| } | ||
|
|
||
| button { | ||
| background-color: #0077cc; | ||
| color: white; | ||
| border: none; | ||
| padding: 10px 15px; | ||
| border-radius: 5px; | ||
| cursor: pointer; | ||
| font-size: 14px; | ||
| min-width: 120px; | ||
| } | ||
|
|
||
| button:hover:not(:disabled) { | ||
| background-color: #005fa3; | ||
| } | ||
|
|
||
| button:disabled { | ||
| background-color: #cccccc; | ||
| cursor: not-allowed; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The html updates are logical!
NTH (Nice to Have/ Not required for completion): semantic html
How might you refactor this to use semantic html to improve accessibility and maintainability? (https://www.freecodecamp.org/news/semantic-html5-elements/)
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.
Thanks for great feedback! I have updated slideshow.js so that clicking the forward or back buttons while auto-advancing now stops the auto-advance as per the acceptance criteria. I also added a test to verify that manual navigation stops auto-advance mode.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks again for the suggestion. I have now wrapped all slideshow controls (manual and automatic) in a single semantic section with a heading. Manual and auto buttons are visually separated into rows, but screen readers and assistive technologies will now recognize all controls as part of one cohesive group. This improves accessibility, semantic clarity, and maintainability without changing the existing functionality.