-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
93 lines (82 loc) · 2 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
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
90
91
92
93
<div id="face" class="face">
<div class="eye">
<div class="parpado"></div>
<span class="eye_ball"></span>
</div>
<div class="eye">
<div class="parpado"></div>
<span class="eye_ball"></span>
</div>
</div>
<style>
.face {
display: flex;
min-height: 100vh;
justify-content: center;
align-items: center;
}
.eye {
border-radius: 50%;
border: 1px solid black;
height: 120px;
width: 200px;
display: inline-block;
margin: 10px;
position: relative;
overflow: hidden;
}
.eye_ball {
content: '';
display: block;
width: 20px;
height: 20px;
background-color: black;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 20px solid #3490da;
z-index: -1;
}
.parpado {
height: 20%;
width: 100%;
background-color: beige;
z-index: 20;
border-bottom: 2px solid burlywood;
}
</style>
<script>
var face = document.getElementById('face');
var eyes = document.getElementsByClassName('eye');
var eyeBalls = document.getElementsByClassName('eye_ball');
var parpados = document.getElementsByClassName('parpado');
function parpadear(eye) {
eye.style.transition = "all ease 0.2s";
eye.style.height = "100%";
setTimeout(function(){
eye.style.transition = "all ease 0.5s";
eye.style.height = "20%";
}, 500);
}
for (var i=0; i < 2; i++) {
eyes[i].addEventListener('click', function(){
parpadear(this.getElementsByClassName('parpado')[0]);
})
}
face.addEventListener('mousemove', function(event){
const x = event.clientX * 100 / this.offsetWidth + "%";
const y = event.clientY * 100 / this.offsetHeight + "%";
for (var i = 0; i < 2; i++) {
eyeBalls[i].style.left = x;
eyeBalls[i].style.top = y;
eyeBalls[i].style.transform = `translate(-${x}, -${y})`;
}
});
setInterval(function(){
for (var i=0; i < 2; i++) {
parpadear(parpados[i]);
}
}, 5000);
</script>