html - CSS 触摸波纹效果,无法正常工作

标签 html css click touch

我的 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/

相关文章:

css - javafx 和 css 代码更改鼠标悬停时的超链接颜色

html - SVG 背景图像不在中心旋转

html - 使用 css 不显示图片

javascript - 如何更改 <animateMotion> 中的 dur 属性?

C# - WPF - 以编程方式创建按钮和单击事件

javascript - jQuery .click() 不工作?

javascript - 如何区分用户点击和 .click()?

html - 元素顶部和底部的空白

html - <div 位置 :absolute;left:Xpx;top>… doesn't work

jquery - 防止父元素上的 CSS 动画应用于子元素