Skip to content
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

SOUTH AFRICA CPT-ITP | LUKE MANYAMAZI | MODULE DATA GROUPS | SLIDE SHOW | WEEK 3 #278

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Sprint-3/slideshow/assets/codingDeskSetup1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sprint-3/slideshow/assets/codingDeskSetup2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Sprint-3/slideshow/assets/codingDeskSetup3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Sprint-3/slideshow/assets/cute-cat-a.png
Binary file not shown.
Binary file removed Sprint-3/slideshow/assets/cute-cat-b.jpg
Binary file not shown.
Binary file removed Sprint-3/slideshow/assets/cute-cat-c.jpg
Binary file not shown.
25 changes: 17 additions & 8 deletions Sprint-3/slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
<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" />
<script defer src="./slideshow.js"></script>
</head>
<body>
<img
id="carousel-img"
src="./assets/codingDeskSetup5.jpg"
alt="coding desk setup"
/>
<button type="button" id="backward-btn">Backwards</button>
<button type="button" id="forward-btn">Forward</button>
<div class="slideshow-container">
<img id="carousel-img" src="" alt="coding desk setup" />
<a class="prev">&#10094;</a>
<a class="next">&#10095;</a>
<a class="autoForward">&#10095;&#10095; Auto Forward</a>
<a class="autoBackward">Auto Backward &#10094;&#10094;</a>
</div>
<div class="dots">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
<button id="stop">Stop</button>
</body>
</html>
37 changes: 37 additions & 0 deletions Sprint-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,42 @@ const images = [
"./assets/codingDeskSetup5.jpg"
];

let slideIndex = 0;
const imgElement = document.getElementById('carousel-img');
const dots = document.getElementsByClassName('dot');

function showSlide(index) {
if (index >= images.length) {
slideIndex = 0;
} else if (index < 0) {
slideIndex = images.length - 1;
} else {
slideIndex = index;
}
imgElement.src = images[slideIndex];
updateDots()
}

function updateDots() {
for (let i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
dots[slideIndex].className += " active";
}

document.querySelector('.prev').addEventListener('click', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a common practice that while selecting your html elements, it is better to organize them at the beginning of your script. You defined your img element at the beginning, also define other elements at the same place.

showSlide(slideIndex - 1);
});
document.querySelector('.next').addEventListener('click', () => {
showSlide(slideIndex + 1);
});

for (let i = 0; i < dots.length; i++) {
dots[i].addEventListener('click', () => {
showSlide(i);
});
}

showSlide(slideIndex);

// Write your code here
109 changes: 108 additions & 1 deletion Sprint-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,108 @@
/** Write your CSS in here **/
* {
box-sizing: border-box;
}

.slideshow-container {
max-width: 800px;
position: relative;
margin-top: 100px;
margin-left: auto;
margin-right: auto;
}

img {
width: 800px;
border-radius: 20px;
}

.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}

.autoForward,
.autoBackward {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: 260px;
padding: 16px;
color: rgb(231, 17, 17);
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}

.next, .autoForward {
right: 0;
}

.prev, .autoBackward {
left: 0;
}

.prev:hover, .next:hover {
background-color: rgba(0, 0, 0, 0.8);
}

.dots {
text-align: center;
}

.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
margin-top: 12px;
}

.dot.active {
background-color: #717171;
}

#carousel-img {
width: 800px;
transition: opacity 0.5s ease-in-out;
opacity: 1;
}

#stop {
display: block;
margin: 20px auto;
padding: 10px 20px;
font-size: 14px;
cursor: pointer;
border: none;
border-radius: 5px;
}

#stop:hover {
background-color: grey;
color: white;
font-weight: bold;
}

.autoBackward,
.autoForward {
color: black;
font-size: 14px;
}