-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.html
112 lines (96 loc) · 2.79 KB
/
Button.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!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>Ripple effect</title>
<style>
:root {
--blue: #0943ff;
--tblue: #0942ffbb;
}
* {
margin: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100vh;
}
button {
font-size: 1.25rem;
padding: 0.5rem 1rem;
border-radius: 8px;
border: 3px solid var(--blue);
color: var(--blue);
background-color: transparent;
transition: all 0.2s;
font-weight: 500;
margin: 2px;
letter-spacing: 1px;
position: relative;
overflow: hidden;
}
button:hover {
background-color: var(--blue);
color: white;
}
button:active {
background-color: #0027a7;
color: white;
}
button:focus {
outline: none;
box-shadow: 0 0 1.5px 3px var(--tblue);
}
button span {
position: absolute;
transform: translate(-50%, -50%);
background-color: #fff;
border-radius: 50%;
pointer-events: none;
animation: ripple 1s;
}
@keyframes ripple {
0% {
width: 0px;
height: 0px;
opacity: 0.5;
}
100% {
width: 500px;
height: 500px;
opacity: 0;
}
}
</style>
</head>
<body>
<button style="width:500px;height:500px">hello</button>
<br>
<button style="width:20rem">hii</button>
</body>
<script>
btns = document.querySelectorAll("button")
btns.forEach(btn => {
btn.onclick = ripple
})
function ripple(e) {
let { clientX, clientY, target } = e;
//let { clientX, clientY } = e;
[clientX, clientY] = [clientX - target.offsetLeft, clientY - target.offsetTop];
//[clientX, clientY] = [clientX - this.offsetLeft, clientY - this.offsetTop];
let ripple = document.createElement("span");
ripple.style.left = clientX + "px";
ripple.style.top = clientY + "px";
this.appendChild(ripple);
setTimeout((element, ripple) => {
element.removeChild(ripple);
}, 1000, this, ripple);
}
</script>
</html>