-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
64 lines (55 loc) · 1.43 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="box">
<div class="side">
<div class="item" id="1"> </div>
<div class="item" id="2"> </div>
<div class="item" id="3"> </div>
<div class="item" id="4"> </div>
<div class="item" id="5"> </div>
<div class="item" id="6"> </div>
</div>
</div>
</body>
</html>
<script>
const items = document.querySelectorAll(".item");
for (item of items) {
item.addEventListener('click', e => {
console.log("点击" + e.target.id);
const id = parseInt(e.target.id) - 1;
// init
for (let i = 1; i <= 6; ++i) {
items[i.toString() - 1].style.borderRadius = "0"
items[i.toString() - 1].style.backgroundColor = "#eee";
}
setTimeout(() => {
items[id].style.backgroundColor = "white";
(id !== 0) && (items[id - 1].style.borderRadius = "0 0 15px 0");
(id !== 5) && (items[id + 1].style.borderRadius = "0 15px 0 0");
}, 200);
})
}
</script>
<style>
.box {
width: 300px;
border: 1px solid #333;
}
.side {
width: 100px;
}
.item {
height: 100px;
width: 100px;
background-color: #eee;
transition: border-radius 0.5s ease, background-color 0.3s linear;
}
</style>