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

NW6 | Sabella Fisseha | JS2 | Image Carousel| WEEK4 #211

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
11 changes: 8 additions & 3 deletions week-3/slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
<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>
<img id="carousel-img" src="./assets/cute-cat-a.png" alt="cat-pic" /><br>
<button type="button" id="auto-backward-btn">Auto Backwards</button>
<button type="button" id="backward-btn">Backwards</button>
<button type="button" id="stop">Stop</button>
<button type="button" id="forward-btn">Forward</button>
</body>
<button type="button" id="auto-forward-btn">Auto Forwards</button>
</div></body>
</html>
38 changes: 37 additions & 1 deletion week-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,40 @@ const images = [
];


// Write your code here
// Write your code here

const forwbutton = document.getElementById("backward-btn");
const backwbutton = document.getElementById("forward-btn");
const imgcontent = document.getElementById("carousel-img");
const autoForward = document.getElementById("auto-forward-btn");
const autobackward = document.getElementById("auto-backward-btn");
const autoStop = document.getElementById("stop");
let autoIntervalId;
let currentIndex = 0;

function forwarding(){
currentIndex = (currentIndex+1 )%images.length;
imgcontent.src = images[currentIndex];
};

function backWarding(){
currentIndex = (currentIndex + 2) % images.length;
imgcontent.src = images[currentIndex];
};

forwbutton.addEventListener("click", forwarding);

backwbutton.addEventListener("click", backWarding);

autoForward.addEventListener("click", ()=> {
autoIntervalId = setInterval(forwarding,2000);
});

autobackward.addEventListener("click", ()=> {

Choose a reason for hiding this comment

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

good Job with the use of Event listeners and intervals! Consider what would happen if you click the autoforward/autobackwards multiple times

autoIntervalId = setInterval(backWarding,2000);
});

autoStop.addEventListener("click",()=>{
clearInterval(autoIntervalId);
});

20 changes: 20 additions & 0 deletions week-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
/** Write your CSS in here **/
body{
background-color: rgb(207, 167, 191);
text-align: center;

}

#carousel-img{
width:40%;
height: 25%;
margin-top: 7%;
border: 10rem solid rgba(174, 94, 94, 0.951);

}
button{
margin-top: 6%;
margin: 1%;
font-size:3em;
padding: 1rem;
border-radius: 25px;
}