-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogly.html
More file actions
73 lines (70 loc) · 1.9 KB
/
googly.html
File metadata and controls
73 lines (70 loc) · 1.9 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
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style media="screen">
@import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap");
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: "Bebas Neue", cursive;
}
.container {
position: absolute;
bottom: 10px;
right: 10px;
display: flex;
}
.container .eyes {
position: relative;
width: 50px;
height: 50px;
display: block;
background-color: #fff;
margin: 0 10px;
border-radius: 50%;
border: 5px solid black
}
.container .eyes::before {
content: "";
top: 50%;
left: 25px;
transform: translate(-50%, -50%);
width: 20px;
height: 20px;
border-radius: 50%;
background: #000;
position: absolute;
border: 4px solid lightgreen;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="container">
<div class="eyes"></div>
<div class="eyes"></div>
</div>
<script type="text/javascript">
document.querySelector("body").addEventListener("mousemove", eyeball);
function eyeball() {
const eye = document.querySelectorAll(".eyes");
eye.forEach(function (eye) {
console.log(eye.getBoundingClientRect().left)
let x = eye.getBoundingClientRect().left + eye.clientWidth / 2;
let y = eye.getBoundingClientRect().top + eye.clientHeight / 2;
let radian = Math.atan2(event.pageX - x, event.pageY - y);
let rotate = radian * (180 / Math.PI) * -1 + 90;
eye.style.transform = "rotate(" + rotate + "deg)";
});
}
</script>
</body>