generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Open
MalusiS
wants to merge
11
commits into
CodeYourFuture:main
Choose a base branch
from
MalusiS:coursework/slideshow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all 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,30 @@ | ||
<!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> | ||
<script defer src="slideshow.js"></script> | ||
<link rel="stylesheet" href="style.css"> | ||
</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> | ||
<img id="carousel-img" src="./images/puppy1.jpg" alt="puppy-pic"> | ||
|
||
<section aria-label="Slideshow controls"> | ||
<h2>Slideshow Controls</h2> | ||
|
||
<!-- Manual navigation buttons --> | ||
<div class="controls"> | ||
<button id="backward-btn">Backwards</button> | ||
<button id="forward-btn">Forward</button> | ||
</div> | ||
|
||
<!-- Automatic navigation buttons --> | ||
<div class="controls"> | ||
<button id="auto-backward">Auto Backwards</button> | ||
<button id="auto-forward">Auto Forward</button> | ||
<button id="stop">Stop</button> | ||
</div> | ||
</section> | ||
</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,66 @@ | ||
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"); | ||
|
||
// Show image helper | ||
function showImage(index) { | ||
carouselImg.src = images[index]; | ||
} | ||
|
||
// Stop auto-advance | ||
function stopAuto() { | ||
clearInterval(intervalId); | ||
intervalId = null; | ||
autoForwardBtn.disabled = false; | ||
autoBackwardBtn.disabled = false; | ||
} | ||
|
||
// Manual navigation | ||
function nextImage() { | ||
if (intervalId) stopAuto(); // stop auto if running | ||
currentIndex = (currentIndex + 1) % images.length; | ||
showImage(currentIndex); | ||
} | ||
|
||
function prevImage() { | ||
if (intervalId) stopAuto(); // stop auto if running | ||
currentIndex = (currentIndex - 1 + images.length) % images.length; | ||
showImage(currentIndex); | ||
} | ||
|
||
forwardBtn.addEventListener("click", nextImage); | ||
backwardBtn.addEventListener("click", prevImage); | ||
|
||
// Auto navigation | ||
function startAuto(directionFn) { | ||
autoForwardBtn.disabled = true; | ||
autoBackwardBtn.disabled = true; | ||
intervalId = setInterval(directionFn, intervalTime); | ||
} | ||
|
||
autoForwardBtn.addEventListener("click", () => startAuto(() => { | ||
currentIndex = (currentIndex + 1) % images.length; | ||
showImage(currentIndex); | ||
})); | ||
|
||
autoBackwardBtn.addEventListener("click", () => startAuto(() => { | ||
currentIndex = (currentIndex - 1 + images.length) % images.length; | ||
showImage(currentIndex); | ||
})); | ||
|
||
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. 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. |
Oops, something went wrong.
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.
NTH/ Not necessary to do: remove duplication
This code is very similar to the prevImage/nextImage code. In your original PR you reused these methods for the auto functionality, which was good.
Suggestion: You have already seen how you can wrap a function around another to add to it (your startAuto function is a wrapper). Perhaps you could use the same idea for your manual navigation functionality.