File tree Expand file tree Collapse file tree 3 files changed +94
-0
lines changed Expand file tree Collapse file tree 3 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ document.querySelector("body").addEventListener("mousemove", eyeball);
2
+
3
+ function eyeball() {
4
+ let eyes = document.querySelectorAll(".eye");
5
+ eyes.forEach((eye) => {
6
+ let x = eye.getBoundingClientRect().left + eye.clientWidth / 2;
7
+ let y = eye.getBoundingClientRect().top + eye.clientHeight / 2;
8
+
9
+ let radian = Math.atan2(event.pageX - x, event.pageY - y);
10
+ let rotate = radian * (180 / Math.PI) * -1 + 270;
11
+ eye.style.transform = `rotate(${rotate}deg)`;
12
+ });
13
+ }
Original file line number Diff line number Diff line change
1
+ <html lang="en">
2
+ <head>
3
+ <meta charset="UTF-8" />
4
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Eyes Following Mouse Cursor</title>
7
+ <link rel="stylesheet" href="style.css" />
8
+ </head>
9
+ <body>
10
+ <div class="emoji-face">
11
+ <div class="eyes">
12
+ <div class="eye"></div>
13
+ <div class="eye"></div>
14
+ </div>
15
+ </div>
16
+
17
+ <script src="app.js"></script>
18
+ </body>
19
+ </html>
Original file line number Diff line number Diff line change
1
+ body {
2
+ margin: 0;
3
+ padding: 0;
4
+ box-sizing: border-box;
5
+ display: flex;
6
+ justify-content: center;
7
+ align-items: center;
8
+ min-height: 100vh;
9
+ background-color: blueviolet;
10
+ }
11
+
12
+ .emoji-face {
13
+ position: relative;
14
+ width: 300px;
15
+ height: 300px;
16
+ background: rgba(255, 255, 0, 0.683);
17
+ border-radius: 50%;
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ transition: 0.5s;
22
+ }
23
+
24
+ .emoji-face::before {
25
+ content: "";
26
+ top: 180px;
27
+ position: absolute;
28
+ width: 150px;
29
+ height: 70px;
30
+ background: crimson;
31
+ border-bottom-left-radius: 70px;
32
+ border-bottom-right-radius: 70px;
33
+ transition: 0.5s;
34
+ }
35
+
36
+ .eyes {
37
+ position: relative;
38
+ top: -40px;
39
+ display: flex;
40
+ }
41
+
42
+ .eyes .eye {
43
+ position: relative;
44
+ width: 80px;
45
+ height: 80px;
46
+ display: block;
47
+ background: white;
48
+ border-radius: 50%;
49
+ margin: 0 15px;
50
+ }
51
+
52
+ .eyes .eye::before {
53
+ content: "";
54
+ position: absolute;
55
+ top: 50%;
56
+ left: 25px;
57
+ transform: translate(-50%, -50%);
58
+ width: 40px;
59
+ height: 40px;
60
+ border-radius: 50%;
61
+ background: black;
62
+ }
You can’t perform that action at this time.
0 commit comments