我在做按钮,按一下就会产生涟漪。然而,波纹却转到了“Axxon”的文本上。
如果您也解决了这个问题,请签入codepen。我只想确保问题得到解决。https://codepen.io/axqua/pen/vwkgvpr
null
const buttons = document.querySelectorAll('a');
buttons.forEach(btn => {
btn.addEventListener('mousedown', function(e) {
let x = e.clientX - e.target.offsetLeft;
let y = e.clientY - e.target.offsetTop;
let ripples = document.createElement('span');
ripples.style.left = x + 'px';
ripples.style.top = y + 'px';
this.appendChild(ripples);
setTimeout(() => {
ripples.remove()
}, 5000);
})
})
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap');
body {
display: flex;
flex-direction: column;
background-color: #141414;
position: center;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: #121212;
background-image: url("");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}
.button {
position: relative;
padding: 12px 36px;
margin: 10px 0;
color: #738adb;
font-size: 26px;
letter-spacing: 2px;
border-radius: 100px;
background: #242424;
overflow: hidden;
font-family: 'Roboto', sans-serif;
text-decoration: none;
}
.div-header-gradient {
display: flex;
align-items: center;
/*justify-content: space-between;*/
background: linear-gradient(#7700ff, #953bff);
height: 100px;
width: 100%;
margin-left: 0px;
overflow: hidden;
animation: animheader;
animation-duration: 1.5s;
/*flex-direction: row;*/
}
.div-header-gradient p {
flex-grow: 1;
/* Add this */
}
span {
position: absolute;
background: #fff;
transform: translate(-50%, -50%);
pointer-events: none;
border-radius: 50%;
pointer-events: none;
animation: ripple 0.6s linear;
z-index: 9999;
overflow: hidden;
}
.text-header-title-white {
color: #fff;
font-size: 70px;
font-family: Roboto, sans-serif;
margin: 1px;
/*position: absolute;*/
vertical-align: central;
overflow: hidden;
margin-left: 0.5%;
display: flex;
flex-direction: row;
}
.href-right-header-buttons {
/*position: absolute;*/
color: #fff;
font-size: 26px;
letter-spacing: 2px;
padding-top: 34px;
padding-bottom: 34px;
padding-left: 6px;
padding-right: 6px;
overflow: hidden;
font-family: 'Roboto', sans-serif;
text-decoration: none;
/*right: 0;
top: 0;*/
animation: animheader;
animation-duration: 1.5s;
}
@keyframes animheader {
from {
margin-top: -100px;
opacity: 0;
}
to {
margin: 0px;
opacity: 1;
}
}
@keyframes ripple {
0% {
width: 0px;
height: 0px;
opacity: 0.2;
}
100% {
width: 400px;
height: 400px;
opacity: 0;
}
}
<div id="particles-js"></div>
<div class="div-header-gradient" style="z-index: 1000;">
<p class="text-header-title-white">
Axxon
</p>
<!--div-->
<a href="#" class="href-right-header-buttons">
Invite Bot
</a>
<a href="#" class="href-right-header-buttons">
More Information
</a>
<!--/div-->
</div>
null
尝试委派和更好的目标定位
我给了链接一个按钮类来测试点击了什么
null
document.querySelector('.div-header-gradient').addEventListener('mousedown', function(e) {
const tgt = e.target;
if (!tgt.classList.contains("button")) return;
let x = tgt.offsetLeft+(tgt.offsetWidth/2);
let y = tgt.offsetTop+(tgt.offsetHeight/2);
let ripples = document.createElement('span');
ripples.style.left = x + 'px';
ripples.style.top = y + 'px';
this.appendChild(ripples);
setTimeout(() => {
ripples.remove()
}, 5000);
})
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap');
body {
display: flex;
flex-direction: column;
background-color: #141414;
position: center;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: #121212;
background-image: url("");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}
.button {
position: relative;
padding: 12px 36px;
margin: 10px 0;
color: #738adb;
font-size: 26px;
letter-spacing: 2px;
border-radius: 100px;
background: #242424;
overflow: hidden;
font-family: 'Roboto', sans-serif;
text-decoration: none;
}
.div-header-gradient {
display: flex;
align-items: center;
/*justify-content: space-between;*/
background: linear-gradient(#7700ff, #953bff);
height: 100px;
width: 100%;
margin-left: 0px;
overflow: hidden;
animation: animheader;
animation-duration: 1.5s;
/*flex-direction: row;*/
}
.div-header-gradient p {
flex-grow: 1;
/* Add this */
}
span {
position: absolute;
background: #fff;
transform: translate(-50%, -50%);
pointer-events: none;
border-radius: 50%;
pointer-events: none;
animation: ripple 0.6s linear;
z-index: 9999;
overflow: hidden;
}
.text-header-title-white {
color: #fff;
font-size: 70px;
font-family: Roboto, sans-serif;
margin: 1px;
/*position: absolute;*/
vertical-align: central;
overflow: hidden;
margin-left: 0.5%;
display: flex;
flex-direction: row;
}
.href-right-header-buttons {
/*position: absolute;*/
color: #fff;
font-size: 26px;
letter-spacing: 2px;
padding-top: 34px;
padding-bottom: 34px;
padding-left: 6px;
padding-right: 6px;
overflow: hidden;
font-family: 'Roboto', sans-serif;
text-decoration: none;
/*right: 0;
top: 0;*/
animation: animheader;
animation-duration: 1.5s;
}
@keyframes animheader {
from {
margin-top: -100px;
opacity: 0;
}
to {
margin: 0px;
opacity: 1;
}
}
@keyframes ripple {
0% {
width: 0px;
height: 0px;
opacity: 0.2;
}
100% {
width: 400px;
height: 400px;
opacity: 0;
}
}
<div id="particles-js"></div>
<div class="div-header-gradient" style="z-index: 1000;">
<p class="text-header-title-white">
Axxon
</p>
<!--div-->
<a href="#" class="button href-right-header-buttons">
Invite Bot
</a>
<a href="#" class="button href-right-header-buttons">
More Information
</a>
<!--/div-->
</div>