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

瀏覽器相容性