HTMLProgressElement: position 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

HTMLProgressElement 接口的只读属性 position 返回 <progress> 元素的当前进度。

对于确定的进度条,它返回当前值除以最大值的计算结果,即一个介于 0.01.0 之间的分数。

对于不确定的进度条,该值始终为 -1

示例

HTML

html
Determinate Progress bar: <progress id="pBar"></progress> Position:
<span>0</span>

JavaScript

js
const pBar = document.getElementById("pBar");
const span = document.getElementsByTagName("span")[0];

pBar.max = 100;
pBar.value = 0;

setInterval(() => {
  pBar.value = pBar.value < pBar.max ? pBar.value + 1 : 0;

  span.textContent = pBar.position;
}, 100);

规范

规范
HTML
# dom-progress-position-dev

浏览器兼容性