This repository was archived by the owner on Feb 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropdown menu.html
More file actions
118 lines (105 loc) · 2.67 KB
/
Dropdown menu.html
File metadata and controls
118 lines (105 loc) · 2.67 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Friends Dropdown</title>
<style>
.dropdown-container {
position: relative;
display: inline-block;
margin-bottom: 10px;
}
.dropdown-btn {
background-color: gray;
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 20px;
}
.dropdown-content {
display: none;
position: absolute;
background-color: gray;
width: 300px;
height: 400px;
padding: 10px;
border-radius: 4px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
overflow-y: auto;
animation: fadeIn 0.5s;
}
.search-input {
width: calc(100% - 20px);
padding: 8px;
margin: 0 auto;
margin-bottom: 10px;
border: none;
border-radius: 4px;
display: block;
}
.search-results {
list-style-type: none;
padding: 0;
margin: 0;
}
.search-result {
padding: 8px;
background-color: #f0f0f0;
border-radius: 4px;
margin-bottom: 5px;
}
.search-result:hover {
background-color: #e0e0e0;
}
.dropdown-container:hover .dropdown-content {
display: block;
animation: fadeIn 0.5s;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
</head>
<body>
<div class="dropdown-container">
<button class="dropdown-btn">Search Friends</button>
<div class="dropdown-content">
<input type="text" placeholder="Search by username" class="search-input">
<ul class="search-results">
</ul>
</div>
</div>
<script>
function searchFriends(query) {
setTimeout(() => {
const results = ['User1', 'User2', 'User3', 'User4', 'User5'];
const searchResultsContainer = document.querySelector('.search-results');
searchResultsContainer.innerHTML = ''; // Clear previous results
results.forEach(result => {
const li = document.createElement('li');
li.classList.add('search-result');
li.textContent = result;
searchResultsContainer.appendChild(li);
});
}, 300);
}
document.querySelector('.search-input').addEventListener('input', function() {
const query = this.value.trim();
if (query !== '') {
searchFriends(query);
}
});
</script>
</body>
</html>