Skip to content

Commit

Permalink
feat($active-header-links): add option for specifying the top offset (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bretterer authored and ulivz committed Nov 16, 2018
1 parent dac42da commit 100bbf2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/@vuepress/plugin-active-header-links/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = (options) => ({
clientRootMixin: path.resolve(__dirname, 'mixin.js'),
define: {
AHL_SIDEBAR_LINK_SELECTOR: options.sidebarLinkSelector || '.sidebar-link',
AHL_HEADER_ANCHOR_SELECTOR: options.headerAnchorSelector || '.header-anchor'
AHL_HEADER_ANCHOR_SELECTOR: options.headerAnchorSelector || '.header-anchor',
AHL_TOP_OFFSET: options.headerTopOffset || 90
}
})
6 changes: 3 additions & 3 deletions packages/@vuepress/plugin-active-header-links/mixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global AHL_SIDEBAR_LINK_SELECTOR, AHL_HEADER_ANCHOR_SELECTOR */
/* global AHL_SIDEBAR_LINK_SELECTOR, AHL_HEADER_ANCHOR_SELECTOR, AHL_TOP_OFFSET */

import throttle from 'lodash.throttle'

Expand Down Expand Up @@ -35,8 +35,8 @@ function getAnchors () {
return {
el,
hash: decodeURIComponent(el.hash),
top: el.getBoundingClientRect().top - 90
/* 90 is to Subtract height of navbar & anchor's padding top */
top: el.getBoundingClientRect().top - AHL_TOP_OFFSET
/* AHL_TOP_OFFSET is to Subtract height of navbar & anchor's padding top */
}
})
}
Expand Down
21 changes: 19 additions & 2 deletions packages/docs/docs/plugin/official/plugin-active-header-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ yarn add -D @vuepress/plugin-active-header-links

```javascript
module.exports = {
plugins: ['@vuepress/active-header-links']
plugins: ['@vuepress/active-header-links']
}
```

### Passing Options
```javascript
module.exports = {
plugins: ['@vuepress/active-header-links', {
sidebarLinkSelector: '.sidebar-link',
headerAnchorSelector: '.header-anchor',
headerTopOffset: 120
}]
}
```

Expand All @@ -32,5 +43,11 @@ module.exports = {
### headerAnchorSelector

- Type: `string`
- Default: `.header-anchor'`
- Default: `.header-anchor`

### headerTopOffset
The number of pixels that you want the header to be from the top of the page before updating the url hash switch to that header.

- Type: `integer`
- Default: `90`

0 comments on commit 100bbf2

Please sign in to comment.