Skip to content

Commit cf95d8d

Browse files
author
Greg Pfaff
committed
adding updates to carousel
1 parent ef6fcbb commit cf95d8d

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

Carousel/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
<main>
1414
<h1> Card Carousel</h1>
1515
<div class="card_carousel_container">
16-
<img data-id="one" class="card one" src='./img/card-svg.svg' />
17-
<img data-id="two" class="card two" src='./img/card-svg.1.svg' />
18-
<img data-id="three" class="card three" src='./img/card-svg.2.svg' />
19-
<img data-id="four" class="card four" src='./img/card-svg.3.svg' />
16+
<div class='card_container'>
17+
<img data-id="one" class="card one" src='./img/card-svg.svg' />
18+
<img data-id="two" class="card two" src='./img/card-svg.1.svg' />
19+
<img data-id="three" class="card three" src='./img/card-svg.2.svg' />
20+
<img data-id="four" class="card four" src='./img/card-svg.3.svg' />
21+
</div>
2022

2123
<div class="card_pagination">
2224
<div class="page" data-id="one"></div>

Carousel/index.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
const buttons = [].slice.call(document.querySelectorAll('.page'));
2+
const cards = [].slice.call(document.querySelectorAll('.card'));
3+
24
let active = false;
35

4-
const activeButtons = (e) => {
5-
console.log("i hate js")
6-
console.log(active);
6+
const activeCards = (event) => {
7+
cards.forEach(card => {
8+
console.log(card.getAttribute('data-id'))
9+
if (card.getAttribute('data-id') === event.getAttribute('data-id')) {
10+
card.style.zIndex = "1"
11+
card.classList.add('active');
12+
card.setAttribute('aria-selected', 'true');
13+
} else {
14+
card.style.zIndex = "0"
15+
card.classList.remove('active');
16+
card.setAttribute('aria-selected', 'false');
17+
}
18+
})
19+
}
20+
21+
const activeButtons = (event) => {
722
if (active == true) {
8-
buttons.forEach(button => button.classList.remove('active'));
23+
activeCards(event.target)
24+
buttons.forEach(button => {
25+
button.classList.remove('active')
26+
button.setAttribute('aria-selected', 'false');
27+
});
928
}
10-
const target = e.target;
11-
target.classList.add('active');
1229
active = true;
30+
const activeButton = event.target;
31+
32+
activeButton.classList.add('active');
33+
activeButton.setAttribute('aria-selected', 'true');
1334
}
1435

15-
buttons.forEach(function (event) {
16-
event.addEventListener('click', activeButtons);
17-
})
36+
buttons.forEach(button => button.addEventListener('click', activeButtons));
1837

1938

2039

Carousel/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ h1 {
7878

7979
.page.active {
8080
background-color: red;
81+
transition: 300ms ease;
8182
}

0 commit comments

Comments
 (0)