【问题标题】:Make radio button's ripple effect work with JS使单选按钮的波纹效果与 JS 一起工作
【发布时间】:2016-09-21 07:00:50
【问题描述】:

我正在研究 Material Design 单选按钮,并试图使其涟漪效应发挥作用,但我在使用正确的 JavaScript 函数时遇到了问题。

基于 MDL,效果会在 mousedown 时激活(不太确定)并且仍然按住它,而在 mouseup 时它会淡出。我已经有了波纹容器,我想我需要一个动画来淡出它,但现在,我会坚持没有动画的基础。

CSS

.radio-ripple {
  position: absolute;
  top: -11px;
  left: -9px;
  height: 40px;
  width: 40px;
  box-sizing: border-box;
  border-radius: 50%;
  z-index: 2;
}
.radio-ripple.is-active {
  background-color: rgba(0,0,0,0.2);
}

我的完整代码JSFiddle。使用jQuery,会容易很多。

我还是个 JS/jQuery 库的初学者,所以来这里寻求帮助。

谢谢

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    我做了一个例子:

    $(function() {
      $('.radio').mousedown(function(e) {
        $(this).find('span').addClass('is-active').fadeIn('fast');
      }).mouseup(function(e) {
        $(this).find('span').addClass('is-active').fadeOut('fast');
      });
    });
    .radio {
      position: relative;  
    }
    
    .radio-ripple {
      position: absolute;
      top: -13px;
      left: -9px;
      height: 40px;
      width: 40px;
      box-sizing: border-box;
      border-radius: 50%;
      z-index: -1;
    }
    .radio-ripple.is-active {
      background-color: #CCC;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div>
      <br/>
      <br/>
      <label class="radio">
        <input type="radio" name="radioActive" />Has ripple
        <span class="radio-ripple 1"></span>
      </label>
      <br/>
      <br/>
      <br/>
      <label class="radio">
        <input type="radio" name="radioActive" />Has also a ripple
        <span class="radio-ripple 2"></span>
      </label>
      <br/>
      <br/>
      <br/>
      <label class="radioButton">
        <input type="radio" name="radioActive" />Ordinary
      </label>
    </div>

    【讨论】:

    • 不,我正在制作我自己版本的材料设计单选按钮。我没有使用 MDL 框架。
    • 我已经更改了示例,我希望这会有所帮助:)
    猜你喜欢
    • 2020-09-13
    • 2021-06-26
    • 1970-01-01
    • 2018-04-08
    • 2015-07-21
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多