-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCssRipple.html
94 lines (80 loc) · 2.59 KB
/
CssRipple.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ripple-Effect Buttons</title>
<style>
:root {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Helvetica Neue", "sans-serif";
}
main {
display: flex;
flex-direction: column;
justify-content: center;
min-height: 100vh;
}
button.ripple:focus {
outline: none;
}
button.ripple {
margin: auto;
text-transform: uppercase;
letter-spacing: .5em;
transform: scale(3);
position: relative;
--ripple-x: 0px;
--ripple-y: 0px;
}
button.ripple::before {
content: "";
pointer-events: none;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background: lightsteelblue;
mix-blend-mode: multiply;
clip-path: circle(0% at var(--ripple-x) var(--ripple-y));
}
button.clicked::before {
animation: ripple ease-in-out 400ms; // note: when changing duration, update the js handler
}
@keyframes ripple {
0% {
clip-path: circle(0% at var(--ripple-x) var(--ripple-y));
}
99% {
clip-path: circle(100% at var(--ripple-x) var(--ripple-y));
}
100% {
clip-path: circle(0% at var(--ripple-x) var(--ripple-y));
}
}
</style>
</head>
<body>
<main>
<button class="ripple"
style="background: linear-gradient(135deg, lightblue, dodgerblue, lightblue);">
Ripple
</button>
<button class="ripple"
style="background: linear-gradient(135deg, orange, red, orange); color: white;">
Ripple
</button>
<button class="ripple" >Ripple</button>
</main>
<script>
const buttons = document.querySelectorAll("button.ripple");
buttons.forEach( button =>
button.onclick = event => {
button.style.setProperty("--ripple-x", event.offsetX+"px");
button.style.setProperty("--ripple-y", event.offsetY+"px");
button.classList.add("clicked");
setTimeout( _ => button.classList.remove("clicked"), 400); // we need to set back for the next click
}
)
</script>
</body>
</html>