-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
fade-out-delete.html
197 lines (187 loc) · 4.64 KB
/
fade-out-delete.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Before Semicolon</title>
<link rel="stylesheet" href="./setup.css">
<style>
body {
background-color: #1eb1d2;
}
@keyframes fadeIn {
100%{
opacity: 1;
}
}
.selector {
width: 300px;
min-height: 50px;
}
.selector .selected-items {
border-radius: 8px;
background-color: #fff;
box-shadow: 0 0 12px #41aed885;
padding: 10px 35px 10px 10px;
min-height: 50px;
position: relative;
}
.selector .selected-items button {
position: absolute;
width: 0;
height: 0;
padding: 0;
top: 40%;
right: 15px;
border-top: 5px solid #222;
border-right: 5px solid #222;
border-bottom: 5px solid transparent;
border-left: 5px solid transparent;
transform: rotate(135deg) translateY(50%);
cursor: pointer;
}
.selector .selected-items button.active {
top: 50%;
border-top: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #222;
border-left: 5px solid #222;
}
.selector .selected-items span {
height: 30px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 10px;
color: #045c60;
}
.selector .selected-items span.label {
display: flex;
justify-content: flex-start;
padding: 0;
}
.selector .selected-items span.selected {
border: 2px solid #41aed8;
padding: 10px;
border-radius: 5px;
margin-right: 8px;
margin-bottom: 5px;
cursor: pointer;
opacity: 0;
animation: fadeIn 0.3s ease forwards;
}
.selector ul {
margin: 10px 0 0 0;
padding: 0;
width: 300px;
list-style: none;
box-shadow: 0 0 12px #41aed885;
border-radius: 8px;
overflow: hidden;
height: 0;
transition: height 0.3s ease;
}
.selector ul.visible {
display: flex;
flex-direction: column;
align-items: center;
}
.selector ul li {
height: 50px;
background-color: #fff;
display: flex;
align-items: center;
padding: 0 15px;
cursor: pointer;
color: #222;
width: 100%;
transition: width 0.15s linear, height 0.3s linear, opacity 0.3s linear, border-radius 0.3s linear;
}
.selector ul li.fade-out,
.selector ul li:active {
background-color: #126eb7;
color: #fff;
}
.selector ul li.fade-out {
width: 0;
height: 0;
opacity: 0;
border-radius: 20%;
color: transparent;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="selector">
<div class="selected-items">
<span class="label">Select Skills...</span>
<button></button>
</div>
<ul class="items">
<li>HTML5</li>
<li>CSS3</li>
<li>Javascript</li>
<li>NodeJs</li>
<li>WordPress</li>
<li>Mongo</li>
</ul>
</div>
<!-- /.dropdown -->
</div>
<script>
const selectorItems = document.querySelector('.selected-items');
const selectorLabel = document.querySelector('.selected-items .label');
const toggleBtn = document.querySelector('.selected-items button');
const listItems = document.querySelector('.items');
const items = document.querySelectorAll('.items li');
const adaptListHeight = () => {
listItems.style.height = (listItems.querySelectorAll('*:not(.fade-out)').length * 50) + 'px';
}
const toggleHideToggleBtn = () => {
if (!listItems.querySelector('*:not(.fade-out)')) {
toggleBtn.style.display = 'none';
} else {
toggleBtn.style.display = 'block';
}
}
const toggleLabelText = () => {
if (selectorItems.querySelector('.selected')) {
selectorLabel.textContent = 'Selected Skills:'
} else {
selectorLabel.textContent = 'Select Skills...'
}
}
items.forEach((item, i) => {
item.addEventListener('click', () => {
item.classList.add('fade-out');
const selectedItem = document.createElement('span');
selectedItem.className = 'selected';
selectedItem.textContent = item.textContent;
selectedItem.addEventListener('click', () => {
item.classList.remove('fade-out');
selectedItem.remove();
toggleHideToggleBtn();
toggleLabelText();
adaptListHeight();
});
selectorItems.insertAdjacentElement('beforeend', selectedItem);
toggleHideToggleBtn();
toggleLabelText();
adaptListHeight();
})
})
toggleBtn.addEventListener('click', () => {
if (listItems.classList.contains('visible')) {
listItems.style.height = 0 + 'px';
} else {
adaptListHeight();
}
listItems.classList.toggle('visible');
toggleBtn.classList.toggle('active');
})
</script>
</body>
</html>