使用材料组件,我试图弄清楚如何使用组件基础的方法。
例如,我有
<div role="progressbar" class="mdc-linear-progress">
<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>
在我的 JS 中,我有
const bar = $('.mdc-linear-progress')[0];
const MDCLinearProgress = mdc.linearProgress.MDCLinearProgress;
const MDCLinearProgressFoundation = mdc.linearProgress.MDCLinearProgressFoundation;
const progress = new MDCLinearProgress(bar);
const progressFoundation = new MDCLinearProgressFoundation(bar);
progressFoundation.setProgress(0.5);
如您所见,我的目标是尝试使用类setProgress
中的方法MDCLinearProgressFoundation
。虽然这不起作用,我不确定我做错了什么,因为它也没有出错。
Codepen - https://codepen.io/ErraticFox/pen/LdwYxb