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 all commits
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 added 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 added 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 added 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 added Sprint-3/slideshow/assets/codingDeskSetup4.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 added Sprint-3/slideshow/assets/codingDeskSetup5.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.
23 changes: 18 additions & 5 deletions Sprint-3/slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<script defer src="slideshow.js"></script>
<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>
<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>
69 changes: 65 additions & 4 deletions Sprint-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,69 @@
const images = [
"./assets/cute-cat-a.png",
"./assets/cute-cat-b.jpg",
"./assets/cute-cat-c.jpg",
"./assets/codingDeskSetup1.jpg",
"./assets/codingDeskSetup2.jpg",
"./assets/codingDeskSetup3.jpg",
"./assets/codingDeskSetup4.jpg",
"./assets/codingDeskSetup5.jpg",
];

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

// Write your code here
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", () => {
stopAuto();
showSlide(slideIndex - 1);
});
document.querySelector(".next").addEventListener("click", () => {
stopAuto();
showSlide(slideIndex + 1);
});

document.querySelector(".autoForward").addEventListener("click", autoForward);
document.querySelector(".autoBackward").addEventListener("click", autoBackward);
document.getElementById("stop").addEventListener("click", stopAuto);

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

function autoForward() {
stopAuto();
showSlide(slideIndex + 1);
autoSlide = setInterval(() => showSlide(slideIndex + 1), 5000);
}

function autoBackward() {
stopAuto();
showSlide(slideIndex - 1);
autoSlide = setInterval(() => showSlide(slideIndex - 1), 5000);
}

function stopAuto() {
clearInterval(autoSlide);
}

showSlide(slideIndex);
116 changes: 115 additions & 1 deletion Sprint-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,115 @@
/** Write your CSS in here **/
* {
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-weight: lighter
}

.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, transform 0.5s ease-in-out;
opacity: 1;
}

#carousel-img.show {
opacity: 1;
transform: scale(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: 12px;
}