-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.html
More file actions
81 lines (78 loc) · 1.8 KB
/
Copy pathmouse.html
File metadata and controls
81 lines (78 loc) · 1.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mouse</title>
</head>
<body>
<div class="ground">
<span class="mouse" id="mouse-a"></span>
<span class="mouse" id="mouse-b"></span>
<span class="mouse" id="mouse-c"></span>
</div>
</body>
</html>
<style>
:root {
background-color: #000000;
}
.ground {
width: 300px;
}
.mouse {
display: block;
background-color: #777777;
width: 50px;
height: 50px;
margin-bottom: 5px;
}
</style>
<script src="jquery-3.5.1.min.js"></script>
<script>
let set_left = function(item) {
item.css("margin-left", "");
item.css("margin-right", "");
}
let set_middle = function(item) {
item.css("margin-left", "auto");
item.css("margin-right", "auto");
}
let set_right = function(item) {
item.css("margin-left", "auto");
item.css("margin-right", "");
}
$(document).ready(function() {
let span_list = [$("#mouse-a"), $("#mouse-b"), $("#mouse-c")];
let span_status = {};
for(let i of span_list) {
let seed = Math.floor(Math.random() * 3);
span_status[i.attr("id")] = seed;
if(seed === 0) {
set_left(i)
}
else if(seed === 1) {
set_middle(i)
}
else if(seed === 2) {
set_right(i)
}
}
$(".mouse").on("mouseenter", function(event) {
let seed = -1;
do {
seed = Math.floor(Math.random() * 3);
}
while(seed === span_status[$(this).attr("id")])
span_status[$(this).attr("id")] = seed;
if(seed === 0) {
set_left($(this))
}
else if(seed === 1) {
set_middle($(this))
}
else if(seed === 2) {
set_right($(this))
}
})
});
</script>