forked from mrlaboratory/the-best-blogger-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rippleButton.html
60 lines (54 loc) · 1.47 KB
/
rippleButton.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ripple Button</title>
<style>
*{
}
button{
border:none;
outline:none;
background-color: #290;
color: white;
padding: 8px 20px;
border-radius: 3px;
box-shadow: 0 2px 2px #bbb;
position: relative;
overflow: hidden;
}
button::before{
content: "";
position: absolute;
background-color: #EEE;
padding: 50%;
border-radius:50%;
left:calc(100% * var(--ripple-x));
top:calc(100% * var(--ripple-y));
transform: translate(-50%, -50%) scale(1);
opacity: 0;
transition: transform 1s, opacity 1s;
}
button:active::before{
transition: 0s;
opacity: 1;
transform: translate(-50%, -50%) scale(0);
}
</style>
</head>
<body>
<button>Click</button>
<button>Button</button>
<script>
var root = document.documentElement;
document.addEventListener('mousedown', ev => {
var el = ev.target;
var x = (ev.clinetX - el.offsetLeft) / el.offsetWith;
var y = (ev.clinetY - el.offseTop) / el.offsetHeight;
root.style.setProperty('--ripple-x', x);
root.style.setProperty('--ripple-y', y);
})
</script>
</body>
</html>