我的CSS触控纹波无法正常工作。当我点击按钮时,它就像中间的气泡一样。请帮忙找出我在哪里做错了。我不太了解CSS动画。我想只用CSS做这个。
cases
.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
}
答案 0 :(得分:4)
只需将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