Welink ui组件介绍Stepper

举报
云会议运营喵大人 发表于 2020/02/18 19:24:29 2020/02/18
【摘要】 Stepper步进器。Stepper UI 提供与WeLink规范一致的视图。<div class="page"> <div class="page__hd"> <h1 class="page__title">Stepper</h1> <p class="page__desc">步进器</p> </div> <div class="page__bd"> <div cl...

Stepper


步进器。Stepper UI 提供与WeLink规范一致的视图。

<div class="page">
  <div class="page__hd">
    <h1 class="page__title">Stepper</h1>
    <p class="page__desc">步进器</p>
  </div>
  <div class="page__bd">
    <div class="weui-cells">
      <div class="weui-cell weui-cell-list weui-cell-stepper">
        <div class="weui-cell__bd">
          主文本
        </div>
        <div class="weui-cell__ft">
          <span class="weui-cell_sub_stepper_minus" onclick="minus()">
            <svg viewBox="0 0 30 2" fill="currentColor"><path d="M0 0h30v2H0z"></path></svg>
          </span>
          <span class="weui-cell_sub_stepper_input">
            <input id="stepperInput" name="stepperVal" type="text" maxlength="6" value="0" />
          </span>
          <span class="weui-cell_sub_stepper_plus" onclick="plus()">
            <svg viewBox="0 0 30 30" fill="currentColor"><path d="M14 14H0v2h14v14h2V16h14v-2H16V0h-2v14z"></path></svg>
          </span>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  var inputEl = document.getElementById("stepperInput");
  var minusEl = document.getElementsByClassName("weui-cell_sub_stepper_minus")[0];
  var plusEl = document.getElementsByClassName("weui-cell_sub_stepper_plus")[0];
  var max = 1000;
  var min = -5;
  var step = 1;
  var defaultVal = 12;
  inputEl.value = defaultVal;
  function getStepperVal() {
    var args = optCall();
    console.log(args);
  }
  function plus() {
    var fn = vel => {
      var valRef = vel + step;
      if (valRef <= max) {
        minusEl.classList.remove("disable");
        return valRef;
      }
      plusEl.classList.add("disable");
      return vel;
    };
    optCall(fn);
  }
  function minus() {
    var fn = vel => {
      var valRef = vel - step;
      if (valRef >= min) {
        plusEl.classList.remove("disable");
        return valRef;
      }
      minusEl.classList.add("disable");
      return vel;
    };
    optCall(fn);
  }
  function optCall(fn) {
    var ref1 = inputEl.value.replace(<span class="hljs-regexp">/[^\d|-]/gi, "");
    var valRef = parseInt(ref1);
    if (fn) {
      inputEl.value = fn(valRef);
    }
    return { el: inputEl, vel: inputEl.value };
  }
</script>

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。