-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteste dropdown.html
89 lines (84 loc) · 2.19 KB
/
teste dropdown.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
button{
background: rgba(10, 101, 176, 0.925);
color: aliceblue;
padding: 10px;
border: none;
border-radius: 10px;
transition: 1s;
cursor: pointer;
}
button:hover{
background: rgb(67, 138, 200);
color: aliceblue;
transition: 1s;
}
.none{
display:none;
}
.active{
height: auto;
border-radius: 10px;
display: flex;
justify-content: start;
}
li{
background: rgba(10, 101, 176, 0.925);
color: aliceblue;
padding: 10px;
border: none;
border-radius: 10px;
list-style: none;
transition: 1s;
width: 90px;
cursor: pointer;
}
li:hover{
background: rgb(67, 138, 200);
color: aliceblue;
transition: 1s;
}
</style>
</head>
<body>
<div class="dropdown">
<button onclick="ativarDropdown()" id="botaoDropdown">Dropdown</button>
<ul id="dropdown" class="none">
<li>Brinquedos pet</li>
<li>Derma</li>
<li>Alimentação</li>
</ul>
</div>
<script>
function ativarDropdown() {
let botaoDropdown = document.getElementById("dropdown");
if (botaoDropdown.classList.contains("active")) {
botaoDropdown.classList.remove("active");
botaoDropdown.classList.add("none");
} else {
botaoDropdown.classList.remove("none");
botaoDropdown.classList.add("active");
}
}
// Função para verificar se o clique foi fora do dropdown
document.addEventListener('click', function(event) {
let botaoDropdown = document.getElementById("dropdown");
let botao = document.querySelector('button');
if (!botaoDropdown.contains(event.target) && !botao.contains(event.target)) {
botaoDropdown.classList.remove("active");
botaoDropdown.classList.add("none");
}
});
</script>
</body>
</html>