aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/timeranges/length/index.html
blob: 1fac25738a989b2a6c39506efcf985a8668d52e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: TimeRanges.length
slug: Web/API/TimeRanges/length
translation_of: Web/API/TimeRanges/length
---
<div>{{APIRef("DOM")}}</div>

<p>只读属性 <strong><code>TimeRanges.length</code></strong> 返回对象中时间范围的个数。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>length</em> = <em>TimeRanges</em>.length;
</pre>

<h2 id="示例">示例</h2>

<p>假定页面中存在一个ID为“myVideo”的 video 元素:</p>

<pre class="brush: js">var v = document.GetElementById("myVideo");

var buf = v.buffered;

var numRanges = buf.length;

if (buf.length == 1) {
  // Only one range
  if (buf.start(0) == 0 &amp;&amp; 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
  }
}
</pre>

<p>这个例子演示了如何通过 <code>TimeRanges</code> 来判断 video 是否已经完全加载。</p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("HTML WHATWG", "#dom-timeranges-length", "TimeRanges.length()")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



<p>{{Compat("api.TimeRanges.length")}}</p>