Skip to content

Commit 4ad3011

Browse files
committed
Chnages the Repel Effect sahandghavidel#6
1 parent 383128a commit 4ad3011

File tree

4 files changed

+71
-35
lines changed

4 files changed

+71
-35
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5502
3+
}

projects/button-ripple-effect/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="style.css" />
99
head>
1010
<body>
11-
<a href="#" class="btn"><span>Buttonspan>a>
11+
<button class="ripple">Click Mebutton>
1212
<script src="index.js">script>
1313
body>
1414
html>
Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1-
const btnEl = document.querySelector(".btn");
1+
// const btnEl = document.querySelector(".btn");
22

3-
btnEl.addEventListener("mouseover", (event) => {
4-
const x = event.pageX - btnEl.offsetLeft;
5-
const y = event.pageY - btnEl.offsetTop;
3+
// btnEl.addEventListener("mouseover", (event) => {
4+
// const x = event.pageX - btnEl.offsetLeft;
5+
// const y = event.pageY - btnEl.offsetTop;
66

7-
btnEl.style.setProperty("--xPos", x + "px");
8-
btnEl.style.setProperty("--yPos", y + "px");
9-
});
7+
// btnEl.style.setProperty("--xPos", x + "px");
8+
// btnEl.style.setProperty("--yPos", y + "px");
9+
// });
10+
const buttons = document.querySelectorAll('.ripple')
11+
12+
buttons.forEach(button => {
13+
button.addEventListener('click', function (e) {
14+
const x = e.pageX
15+
const y = e.pageY
16+
17+
const buttonTop = e.target.offsetTop
18+
const buttonLeft = e.target.offsetLeft
19+
20+
const xInside = x - buttonLeft
21+
const yInside = y - buttonTop
22+
23+
const circle = document.createElement('span')
24+
circle.classList.add('circle')
25+
circle.style.top = yInside + 'px'
26+
circle.style.left = xInside + 'px'
27+
28+
this.appendChild(circle)
29+
30+
setTimeout(() => circle.remove(), 500)
31+
})
32+
})
Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,53 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
17
body {
2-
margin: 0;
8+
background-color: #000;
9+
font-family: 'Roboto', sans-serif;
310
display: flex;
11+
flex-direction: column;
12+
align-items: center;
413
justify-content: center;
514
height: 100vh;
6-
align-items: center;
7-
background-color: aliceblue;
8-
font-family: sans-serif;
15+
overflow: hidden;
16+
margin: 0;
917
}
1018

11-
.btn {
12-
background-color: pink;
13-
padding: 20px 40px;
14-
border-radius: 5px;
15-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
16-
text-decoration: none;
17-
color: black;
18-
position: relative;
19+
button {
20+
background-color: rgb(225, 12, 147);
21+
color: #fff;
22+
border: 1px rgb(235, 21, 89) solid;
23+
font-size: 14px;
24+
text-transform: uppercase;
25+
letter-spacing: 2px;
26+
padding: 20px 30px;
1927
overflow: hidden;
28+
margin: 10px 0;
29+
position: relative;
30+
border-radius: 4px;
2031
}
2132

22-
.btn span {
23-
position: relative;
24-
z-index: 1;
33+
button:focus {
34+
outline: none;
2535
}
2636

27-
.btn::before {
28-
content: "";
37+
button .circle {
2938
position: absolute;
30-
background-color: orangered;
31-
width: 0;
32-
height: 0;
33-
left: var(--xPos);
34-
top: var(--yPos);
35-
transform: translate(-50%, -50%);
39+
background-color: #fff;
40+
width: 100px;
41+
height: 100px;
3642
border-radius: 50%;
37-
transition: width 0.5s, height 0.5s;
43+
transform: translate(-50%, -50%) scale(0);
44+
animation: scale 0.5s ease-out;
3845
}
3946

40-
.btn:hover::before {
41-
width: 300px;
42-
height: 300px;
47+
@keyframes scale {
48+
to {
49+
transform: translate(-50%, -50%) scale(3);
50+
opacity: 0;
51+
}
4352
}
53+

0 commit comments

Comments
 (0)