TimeRanges: length 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

TimeRanges.length 只讀屬性返回物件中範圍的數量。

一個數字。

示例

給出一個 ID 為 "myVideo" 的影片元素

js
const v = document.getElementById("myVideo");

const buf = v.buffered;

const numRanges = buf.length;

if (buf.length === 1) {
  // Only one range
  if (buf.start(0) === 0 && buf.end(0) === v.duration) {
    // The one range starts at the beginning and ends at
    // the end of the video, so the whole thing is loaded
  }
}

此示例檢視時間範圍,並檢查是否已載入整個影片。

規範

規範
HTML
# dom-timeranges-length-dev

瀏覽器相容性