generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 158
WESTMIDLANDS| ITP-MAY2025| SARA TAHIR| Feature/slideshow #682
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9bf0a6a
Updated HTML title and added a link to the style sheet
SaraTahir28 9b3910d
Added functionality for forward and backward button
SaraTahir28 e751dc3
Added some styling to ensure all images are uniform in size
SaraTahir28 1b6b0c9
Added Buttons for Autoforward, AutoBackwards and stop
SaraTahir28 1e990f5
Added functions for Autoforward,AutoBackward and Stop
SaraTahir28 d292efc
Added a title and updated the style sheet.
SaraTahir28 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
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,57 @@ | ||
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", | ||
"https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=800&q=80", | ||
] | ||
|
||
|
||
// Write your code here | ||
let currentIndex = 0; | ||
const carouselImg = document.getElementById("carousel-img"); | ||
|
||
function showNextImage() { | ||
currentIndex++; | ||
if (currentIndex >= images.length) { | ||
currentIndex = 0; // wrap to start | ||
} | ||
carouselImg.src = images[currentIndex]; | ||
} | ||
document.getElementById("forward-btn").addEventListener("click",function(){ | ||
showNextImage() | ||
|
||
}) | ||
function showPreviousImage() { | ||
currentIndex--; | ||
if (currentIndex < 0) { | ||
currentIndex = images.length - 1; // assign the last index to currentIndex | ||
} | ||
carouselImg.src = images[currentIndex]; | ||
} | ||
document.getElementById("backward-btn").addEventListener("click",function(){ | ||
showPreviousImage() | ||
|
||
}) | ||
let autoForwardIntervalId; | ||
let autoBackwardIntervalId // declared once globally or at the top of your JS file | ||
|
||
function startAutoForward() { | ||
clearInterval(autoForwardIntervalId); | ||
autoForwardIntervalId = setInterval(showNextImage, 2000); | ||
} | ||
document.getElementById("auto-forward-btn").addEventListener("click", function() { | ||
startAutoForward(); | ||
}); | ||
function setAutoBackwards(){ | ||
clearInterval(autoBackwardIntervalId); | ||
autoBackwardIntervalId = setInterval(showPreviousImage,2000); | ||
} | ||
document.getElementById("auto-backward-btn").addEventListener("click", function() { | ||
setAutoBackwards(); | ||
}); | ||
function stopSlideshow() { | ||
clearInterval(autoForwardIntervalId); | ||
clearInterval(autoBackwardIntervalId); | ||
} | ||
document.getElementById("stop-btn").addEventListener("click", function() { | ||
stopSlideshow(); | ||
}); |
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,66 @@ | ||
/** Write your CSS in here **/ | ||
/* Center everything and add some spacing */ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f0f4f8; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: 30px 20px; | ||
} | ||
|
||
/* Style the carousel image */ | ||
#carousel-img { | ||
width: 350px; | ||
height: 230px; | ||
object-fit: contain; | ||
border: 4px solid #4a90e2; | ||
border-radius: 12px; | ||
box-shadow: 0 4px 10px rgba(0,0,0,0.15); | ||
margin-bottom: 25px; | ||
background-color: white; | ||
} | ||
|
||
/* Style all buttons uniformly */ | ||
h1 { | ||
font-size: 2rem; | ||
color: #333; | ||
margin-bottom: 20px; | ||
text-align: center; | ||
font-family: 'Arial', sans-serif; | ||
} | ||
button { | ||
background-color: #a9457c; | ||
color: white; | ||
border: none; | ||
padding: 12px 20px; | ||
margin: 5px 8px; | ||
font-size: 16px; | ||
border-radius: 6px; | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; | ||
box-shadow: 0 3px 6px rgba(74,144,226,0.5); | ||
} | ||
|
||
/* Hover effect on buttons */ | ||
button:hover { | ||
background-color: #357ABD; | ||
} | ||
|
||
/* Optional: Add focus outline for accessibility */ | ||
button:focus { | ||
outline: 2px solid #357ABD; | ||
outline-offset: 2px; | ||
} | ||
|
||
/* Responsive tweak: smaller on narrow screens */ | ||
@media (max-width: 400px) { | ||
#carousel-img { | ||
width: 90vw; | ||
height: auto; | ||
} | ||
button { | ||
width: 100%; | ||
margin: 8px 0; | ||
} | ||
} |
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.
Interleaving your functions and the event listener registration makes it a bit hard to see which event listeners are actually being wired up. Can you think how to organise your code so it's easier to see which things are actually being done on page load?