我的 CSS 触摸波纹无法正常工作。当我点击按钮时,它看起来就像中心的一个气泡。请帮助找出我在哪里做错了。我对 CSS 动画不太了解。我想仅使用 CSS 来完成此操作。
.ripple-con,
.button {
display: inline-block;
position: relative;
overflow: hidden;
}
.button::after,
.ripple {
content: ' ';
background: rgba(0, 0, 0, 0.3);
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
display: inline-block;
border-radius: 100%;
}
.button:active::after,
.ripple:active,
.button:active+.ripple {
animation: ripple 2s;
}
@keyframes ripple {
to {
opacity: 0;
margin: -250px;
width: 500px;
height: 500px;
}
}
.button {
line-height: 39px;
border: 0;
height: 42px;
box-sizing: border-box;
padding: 0 20px;
background: #888;
border-radius: 5px;
cursor: default;
vertical-align: top;
}
html {
text-align: center
}
body {
display: inline-block
}
<div class="ripple-con">
<input class="button" type="submit" value="Submit Button : Button">
<span class="ripple"></span>
</div>
<div class="ripple-con">
<input class="button" type="button" value="Input Button : Button">
<span class="ripple"></span>
</div>
<div class="button">Div : Button</div>
<button class="button">Button : Button</button>
最佳答案
只需将 animation:ripple
放置在 .button::after, .ripple
样式定义中,并将 animation: none
放置在其激活的位置如下
.ripple-con,
.button {
display: inline-block;
position: relative;
overflow: hidden;
}
.button::after,
.ripple {
content: ' ';
background: rgba(0, 0, 0, 0.3);
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
display: inline-block;
border-radius: 100%;
animation: ripple 2s;
}
.button:active::after,
.ripple:active,
.button:active + .ripple {
animation: none;
}
@keyframes ripple {
to {
opacity: 0;
margin: -250px;
width: 500px;
height: 500px;
}
}
.button {
line-height: 39px;
border: 0;
height: 42px;
box-sizing: border-box;
padding: 0 20px;
background: #888;
border-radius: 5px;
cursor: default;
vertical-align: top;
}
html {
text-align: center
}
body {
display: inline-block
}
<div class="ripple-con">
<input class="button" type="submit" value="Submit Button : Button">
<span class="ripple"></span>
</div>
<div class="ripple-con">
<input class="button" type="button" value="Input Button : Button">
<span class="ripple"></span>
</div>
<div class="button">Div : Button</div>
<button class="button">Button : Button</button>
这是fiddle
关于html - CSS 触摸波纹效果,无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35548242/