aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/history/scrollrestoration/index.html
blob: 77c607304c34fe59774c9263b9d9876cda4a25d3 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
title: History.scrollRestoration
slug: Web/API/History/scrollRestoration
tags:
  - API
  - HTML DOM
  - History
  - History API
  - Property
  - Reference
translation_of: Web/API/History/scrollRestoration
---
<div>{{APIRef("History API")}}</div>

<div></div>

<p>{DOMxRef("History"))的接口——<strong><code>滚动恢复属性</code></strong>允许web应用程序在历史导航上显式地设置默认滚动恢复行为</p>

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

<pre class="syntaxbox">const <em>scrollRestore</em> = history.scrollRestoration</pre>

<h3 id="值"></h3>

<dl>
 <dt><code>auto</code></dt>
 <dd>将恢复用户已滚动到的页面上的位置。</dd>
 <dt><code>manual</code></dt>
 <dd>未还原页上的位置。用户必须手动滚动到该位置。</dd>
</dl>

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

<h3 id="查看当前页面滚动恢复行为">查看当前页面滚动恢复行为</h3>

<pre class="brush: js">const scrollRestoration = history.scrollRestoration
if (scrollRestoration === 'manual') {
  console.log('The location on the page is not restored, user will need to scroll manually.');
}
</pre>

<h3 id="防止自动恢复页面位置">防止自动恢复页面位置</h3>

<pre class="brush: js">if (history.scrollRestoration) {
  history.scrollRestoration = 'manual';
}
</pre>

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

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">评论</th>
  </tr>
  <tr>
   <td>{{SpecName("HTML WHATWG", "#scroll-restoration-mode", "scroll restoration mode")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td>No change from {{SpecName("HTML5 W3C")}}.</td>
  </tr>
  <tr>
   <td>{{SpecName("HTML5 W3C", "browsers.html#dom-history-scrollrestoration", "History.scrollRestoration")}}</td>
   <td>{{Spec2("HTML5 W3C")}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

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



<p>{{Compat("api.History.scrollRestoration")}}</p>