Skip to content

Commit

Permalink
completed button ripple
Browse files Browse the repository at this point in the history
  • Loading branch information
tsr-kairi committed Jul 5, 2021
1 parent b14d854 commit 9a09183
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Day 20 - Button Ripple Effect/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Block elements and variables

const buttons = document.querySelectorAll(".ripple");

buttons.forEach((button) => {
button.addEventListener("click", function (e) {
const x = e.clientX;
const y = e.clientY;

const buttonTop = e.target.offsetTop;
const buttonLeft = e.target.offsetLeft;

const xInside = x - buttonLeft;
const yInside = y - buttonTop;

const circle = document.createElement("span");
circle.classList.add("circle");
circle.style.top = yInside + "px";
circle.style.left = xInside + "px";

this.appendChild(circle);

setTimeout(() => circle.remove(), 500);
});
});
19 changes: 19 additions & 0 deletions Day 20 - Button Ripple Effect/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!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" />
<link
href="https://fonts.googleapis.com/css2?family=Heebo:wght@300&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="./style.css" />
<title>Button Ripple Effect</title>
</head>
<body>
<button class="ripple">Click me</button>

<script src="./app.js"></script>
</body>
</html>
52 changes: 52 additions & 0 deletions Day 20 - Button Ripple Effect/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
*::after,
*::before {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
background-color: #000;
font-family: "Heebo", sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
margin: 0;
}

button {
cursor: pointer;
background-color: purple;
color: #fff;
border: 1px purple solid;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 2px;
padding: 20px 30px;
overflow: hidden;
margin: 10px 0;
position: relative;
}

button:focus {
outline: none;
}

button .circle {
position: absolute;
background-color: #fff;
width: 100px;
height: 100px;
border-radius: 50%;
transform: translate(-50%, -50%) scale(0);
animation: scale 0.5s ease-out;
}

@keyframes scale {
to {
transform: translate(-50%, -50%) scale(3);
opacity: 0;
}
}

0 comments on commit 9a09183

Please sign in to comment.