【问题标题】:Working example of Material Design LinearProgress componentMaterial Design LinearProgress 组件的工作示例
【发布时间】:2018-12-27 17:12:12
【问题描述】:

附件是尝试制作线性进度组件的工作原型的伪代码。

HTML

<script src="https://unpkg.com/material-components-web@0.42.1/dist/material-components-web.min.js"></script>
...
<div role="progressbar" class="mdc-linear-progress" id="my-progress-bar">
    <div class="mdc-linear-progress__buffering-dots"></div>
    <div class="mdc-linear-progress__buffer"></div>
    <div class="mdc-linear-progress__bar mdc-linear-progress__primary-bar">
        <span class="mdc-linear-progress__bar-inner"></span>
    </div>
    <div class="mdc-linear-progress__bar mdc-linear-progress__secondary-bar">
        <span class="mdc-linear-progress__bar-inner"></span>
    </div>
</div>

JavaScript

const overallProgress = mdc.linearProgress.MDCLinearProgress.attachTo(document.getElementById('my-progress-bar'));
overallProgress.setProgress(0.5);

上述代码旨在显示 50% 的进度。原型不起作用。它的哪一部分可能出错了?以下参考资料是我能从官方参考文件中得到的最好的参考资料。

参考文献

  1. Linear Progress, Material Design for Web
  2. Linear Progress Demo, Material Design for Web

【问题讨论】:

    标签: javascript html material-components-web


    【解决方案1】:

    TL;DR

    只需替换 JavaScript 行 overallProgress.setProgress(0.5); 转入overallProgress.progress=0.5;

    详情

    我挖掘了source-code of MDCLinearProgress,结果发现它是使用JavaScript function setters 实现的。函数设置器的工作方式是在类中声明为方法,但实际设置值是将其视为属性。

    所以不要使用setProgress(value),而是将其替换为progress=value

    【讨论】:

    • 他们为什么要写使用setProgress?
    猜你喜欢
    • 2015-05-07
    • 1970-01-01
    • 2018-12-26
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    相关资源
    最近更新 更多