Skip to content

Commit d9ebafd

Browse files
authored
Added alwaysScrollHeader option
1 parent a8f9fc1 commit d9ebafd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

docs/configuration.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ window.$docsify = {
6262
};
6363
```
6464

65+
## alwaysScrollHeader
66+
67+
- Type: `Boolean`
68+
- Default: `false`
69+
70+
Always scrolls to ID/header when specified in route. By default, page will use browser's scroll auto-restoration.
71+
72+
```js
73+
window.$docsify = {
74+
alwaysScrollHeader: true,
75+
};
76+
```
77+
6578
## autoHeader
6679

6780
- Type: `Boolean`

src/core/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function (vm) {
77
const config = merge(
88
{
99
auto2top: false,
10+
alwaysScrollHeader: false,
1011
autoHeader: false,
1112
basePath: '',
1213
catchPluginErrors: true,

src/core/event/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { scrollIntoView, scroll2Top } from './scroll';
1212
export function Events(Base) {
1313
return class Events extends Base {
1414
$resetEvents(source) {
15-
const { auto2top } = this.config;
15+
const { auto2top, alwaysScrollHeader } = this.config;
1616

1717
(() => {
18-
// Rely on the browser's scroll auto-restoration when going back or forward
18+
// If alwaysScrollHeader is false (default), rely on the browser's scroll auto-restoration when going back or forward
1919
if (source === 'history') {
20-
return;
20+
alwaysScrollHeader && scrollIntoView(this.route.path, this.route.query.id);
2121
}
2222
// Scroll to ID if specified
2323
if (this.route.query.id) {

0 commit comments

Comments
 (0)