Skip to content

Commit 2cebd42

Browse files
committed
Add styling to club section and scripting to make it a collapsible list
1 parent b001bb4 commit 2cebd42

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

script.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const hobbies = document.getElementsByClassName("hobbies");
2+
const clubs = document.getElementsByClassName("clubs");
23
const swenList = document.querySelector("ul.swen_list");
34
var info = document.createElement("li");
45
info.textContent = "Click here to add a new list item";
56
swenList.appendChild(info);
67

78
for (var index = 0; index < hobbies.length; index++) {
89
hobbies[index].addEventListener("click", async function() {
9-
this.classList.toggle("active");
10+
this.classList.toggle("hobbies_active");
1011
var content = this.nextElementSibling;
1112

1213
if (content.style.maxHeight) {
@@ -19,6 +20,22 @@ for (var index = 0; index < hobbies.length; index++) {
1920
});
2021
}
2122

23+
for (var index = 0; index < clubs.length; index++) {
24+
clubs[index].addEventListener("click", async function() {
25+
this.classList.toggle("clubs_active");
26+
var content = this.nextElementSibling;
27+
28+
if (content.style.maxHeight) {
29+
content.style.maxHeight = null;
30+
}
31+
32+
else {
33+
content.style.maxHeight = content.scrollHeight + "px";
34+
}
35+
});
36+
}
37+
38+
2239
info.onclick = async function() {
2340
const listItem = document.createElement("li");
2441
const listContent = prompt("Enter a list item: ");

style.css

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ main > :not(hr), footer {
7575
.about_me img {
7676
float: right;
7777
border: 2px solid #333;
78-
margin-left: 10px;
78+
margin-left: 20px;
7979
margin-bottom: 30px;
8080
max-width: 20%;
8181
height: auto;
@@ -93,9 +93,10 @@ main > :not(hr), footer {
9393
content: '\002B Hobbies';
9494
font-weight: bold;
9595
font-size: 22px;
96+
margin-bottom: 0px;
9697
}
9798

98-
.active:after {
99+
.hobbies_active:after {
99100
content: '\2212 Hobbies';
100101
}
101102

@@ -111,6 +112,32 @@ main > :not(hr), footer {
111112
margin-right: 10%;
112113
}
113114

115+
.clubs {
116+
background-color: transparent;
117+
border-width: 0;
118+
font-family: inherit;
119+
font-style: inherit;
120+
margin-left: 20px;
121+
margin-top: 30px;
122+
}
123+
124+
.clubs:after {
125+
content: '\002B Clubs';
126+
font-weight: bold;
127+
font-size: 22px;
128+
}
129+
130+
.clubs_active:after {
131+
content: '\2212 Clubs';
132+
}
133+
134+
#clubs_content {
135+
line-height: 25px;
136+
max-height: 0;
137+
overflow: hidden;
138+
transition: max-height 0.2s ease-out;
139+
}
140+
114141
.schedule table {
115142
border: 2px solid black;
116143
background-color: rgb(211, 234, 250)

0 commit comments

Comments
 (0)