This repository was archived by the owner on Dec 18, 2024. It is now read-only.
generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 40
NW-6 | Fikret Ellek | JS2| [TECH ED] Slideshow-Extra| WEEK-4 #227
Open
fikretellek
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
fikretellek:week-4/slideshow-extra
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
8 commits
Select commit
Hold shift + click to select a range
bd73e06
level 1 implemented
fikretTest 9906166
started for level 2, buttons added ın html
fikretTest 5fad378
autoplay functions added
fikretTest a0eda2e
stop autoplay function added
fikretTest e24b044
editted css
fikretTest 6f8f722
when clicked on the both autoplay buttons, overlaping bug detected. F…
fikretTest 802abc8
css added, js updated
fikretTest 9617c62
id conflict between test.js file is resolved. All tests passed
fikretTest 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,131 @@ | ||
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", | ||
]; | ||
|
||
let currentPhotoIndex = 0; | ||
|
||
// Write your code here | ||
const image = document.getElementById("carousel-img"); | ||
|
||
const imgContainer = document.createElement("div"); | ||
imgContainer.setAttribute("id", "img-container"); | ||
|
||
image.before(imgContainer); | ||
imgContainer.appendChild(image); | ||
|
||
const btnContainer = document.createElement("div"); | ||
btnContainer.classList.add("btn-container"); | ||
|
||
const backwardBtn = document.getElementById("backward-btn"); | ||
const forwardBtn = document.getElementById("forward-btn"); | ||
|
||
const stopBtn = document.getElementById("stop"); | ||
|
||
const autoBackwardBtn = document.getElementById("auto-backward"); | ||
const autoForwardBtn = document.getElementById("auto-forward"); | ||
|
||
btnContainer.append( | ||
autoBackwardBtn, | ||
backwardBtn, | ||
stopBtn, | ||
forwardBtn, | ||
autoForwardBtn | ||
); | ||
|
||
let autoPlayBackward; | ||
let autoPlayForward; | ||
|
||
// Write your code here | ||
|
||
function generatePhoto() { | ||
image.setAttribute("src", images[currentPhotoIndex]); | ||
if (currentPhotoIndex === 0) { | ||
document.getElementById("img0").style.backgroundColor = "grey"; | ||
document.getElementById("img1").style.backgroundColor = "black"; | ||
document.getElementById("img2").style.backgroundColor = "black"; | ||
} else if (currentPhotoIndex === 1) { | ||
document.getElementById("img0").style.backgroundColor = "black"; | ||
document.getElementById("img1").style.backgroundColor = "grey"; | ||
document.getElementById("img2").style.backgroundColor = "black"; | ||
} else if (currentPhotoIndex === 2) { | ||
document.getElementById("img0").style.backgroundColor = "black"; | ||
document.getElementById("img1").style.backgroundColor = "black"; | ||
document.getElementById("img2").style.backgroundColor = "grey"; | ||
} | ||
} | ||
|
||
function nextPhoto() { | ||
++currentPhotoIndex; | ||
if (currentPhotoIndex === 3) { | ||
currentPhotoIndex = 0; | ||
} | ||
generatePhoto(); | ||
} | ||
|
||
function previousPhoto() { | ||
--currentPhotoIndex; | ||
if (currentPhotoIndex === -1) { | ||
currentPhotoIndex = 2; | ||
} | ||
generatePhoto(); | ||
} | ||
|
||
backwardBtn.addEventListener("click", previousPhoto); | ||
forwardBtn.addEventListener("click", nextPhoto); | ||
|
||
autoBackwardBtn.addEventListener("click", () => { | ||
autoPlayBackward = setInterval(() => { | ||
previousPhoto(); | ||
}, 2000); | ||
clearInterval(autoPlayForward); | ||
autoBackwardBtn.disabled = true; | ||
autoForwardBtn.disabled = true; | ||
}); | ||
|
||
autoForwardBtn.addEventListener("click", () => { | ||
autoPlayForward = setInterval(() => { | ||
nextPhoto(); | ||
}, 2000); | ||
clearInterval(autoPlayBackward); | ||
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. Same here! |
||
autoBackwardBtn.disabled = true; | ||
autoForwardBtn.disabled = true; | ||
}); | ||
|
||
stopBtn.addEventListener("click", () => { | ||
clearInterval(autoPlayBackward); | ||
clearInterval(autoPlayForward); | ||
autoBackwardBtn.disabled = false; | ||
autoForwardBtn.disabled = false; | ||
}); | ||
|
||
window.onload = generatePhoto; | ||
|
||
// extra img navigate buttons | ||
|
||
const navContainer = document.createElement("div"); | ||
navContainer.classList.add("nav"); | ||
|
||
for (let i = 0; i < images.length; i++) { | ||
const imgBtn = document.createElement("button"); | ||
imgBtn.classList.add(`img${i}`); | ||
imgBtn.setAttribute("id", `img${i}`); | ||
imgBtn.classList.add("navBtn"); | ||
navContainer.appendChild(imgBtn); | ||
Comment on lines
+111
to
+114
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. Same here as I mentioned in the previous message, you created the element and then appended it to the DOM. Well done! |
||
} | ||
|
||
imgContainer.after(navContainer); | ||
navContainer.after(btnContainer); | ||
|
||
navContainer.addEventListener("click", (event) => { | ||
const target = event.target; | ||
if (target.classList.contains("img0")) { | ||
currentPhotoIndex = 0; | ||
} else if (target.classList.contains("img1")) { | ||
currentPhotoIndex = 1; | ||
} else if (target.classList.contains("img2")) { | ||
currentPhotoIndex = 2; | ||
} | ||
|
||
generatePhoto(); | ||
}); |
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,79 @@ | ||
/** Write your CSS in here **/ | ||
* { | ||
margin: 0px; | ||
padding: 0px; | ||
border: none; | ||
} | ||
body { | ||
height: 80vh; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin: 5vh 5vw; | ||
border-radius: 27px; | ||
border: solid 3px black; | ||
padding: 5vh 5vw; | ||
background-color: rgb(206, 206, 206); | ||
} | ||
#img-container { | ||
width: 80vw; | ||
height: 60vh; | ||
border-radius: 15px; | ||
border: solid 3px black; | ||
} | ||
#carousel-img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
z-index: -1; | ||
border-radius: 12px; | ||
} | ||
|
||
.nav { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 10px; | ||
} | ||
|
||
.navBtn { | ||
padding: 10px 10px; | ||
border-radius: 999px; | ||
background-color: black; | ||
} | ||
|
||
.btn-container { | ||
display: flex; | ||
flex-direction: row; | ||
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 design, well done. Small note: you don't need to specify |
||
gap: 10px; | ||
} | ||
|
||
.btn-container button { | ||
padding: 5px 10px 6px; | ||
border-radius: 999px; | ||
background-color: black; | ||
color: white; | ||
font-size: 17px; | ||
} | ||
.btn-container button:hover { | ||
background-color: grey; | ||
} | ||
#auto-backward-btn { | ||
padding-right: 14px; | ||
} | ||
#backward-btn { | ||
padding-right: 14px; | ||
} | ||
#auto-forward-btn { | ||
padding-left: 14px; | ||
} | ||
#forward-btn { | ||
padding-left: 14px; | ||
} | ||
#auto-backward-btn { | ||
padding-right: 14px; | ||
} | ||
#stop-btn { | ||
padding-right: 15px; | ||
padding-left: 15px; | ||
} |
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.
I love this! it clears other intervals when you change the slide direction - such a thoughtful touch! Well done!