Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

NW6 | Orlando_Morales | JS2 - Slideshow | Week3 #212

Open
wants to merge 1 commit 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
7 changes: 5 additions & 2 deletions week-3/slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<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" />
<div class="image-container">
<img id="carousel-img" src="./assets/cute-cat-a.png" alt="cat-pic" />
</div>
<button type="button" id="backward-btn">Backwards</button>
<button type="button" id="forward-btn">Forward</button>
</body>
Expand Down
32 changes: 28 additions & 4 deletions week-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
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",
];

// Write your code here
let currentIndex = 0;
const imgDisplay = document.getElementById("carousel-img");
const btnBack = document.getElementById("backward-btn");
const btnForward = document.getElementById("forward-btn");

// Write your code here
function updateImage() {
imgDisplay.src = images[currentIndex];
}

function goBack() {
if (currentIndex > 0) {
currentIndex--;
updateImage();
}
}

function goForward() {
if (currentIndex < images.length - 1) {
currentIndex++;
updateImage();
}
}

btnBack.addEventListener("click", goBack);
btnForward.addEventListener("click", goForward);
27 changes: 27 additions & 0 deletions week-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
/** Write your CSS in here **/

body {
display: flex;
flex-direction: column;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
margin: 20px;
}

.image-container {
width: 300px;
height: 300px;
overflow: hidden;
margin-bottom: 10px;
}

#carousel-img {
width: 100%;
height: auto;
}

button {
font-size: 16px;
padding: 10px;
margin: 5px;
cursor: pointer;
}