Skip to content

Commit 1008b4e

Browse files
authored
fix: avoid obscuring heading behind navbar when following permalinks (#630)
Fixes #629. Ref #588.
1 parent 72dd271 commit 1008b4e

2 files changed

Lines changed: 5 additions & 28 deletions

File tree

styles/components/anchors.less

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,8 @@ h1, h2, h3 {
7575
}
7676
}
7777

78-
79-
// Offset
80-
// ----------------------------------------------
81-
// anchor targets are invisible and set the specified
82-
// distance above headings and anchors. This is what
83-
// ensures that our headings won't overlap the navbar.
84-
// If you require clickable anchors, you can
85-
// achieve this with fewer classes and less HTML
86-
87-
.anchor-target {
88-
position: absolute;
89-
margin-top: -(@anchor-distance);
90-
padding-top: @anchor-distance;
91-
width: 2px;
92-
}
93-
94-
.anchor-target-small {
95-
margin-top: -(@anchor-distance-small);
96-
padding-top: @anchor-distance-small;
78+
// anchor targets are invisible anchors for compatibility with
79+
// previous headings and URLs that have been moved or renamed.
80+
h1, h2, h3, .anchor-target {
81+
scroll-margin-top: @anchor-distance;
9782
}

templates/_plugins/navigation.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ module.exports = function navigationPlugin(params, callback) {
9999
$(navOpts.id || '#navigation').append(buildHTML(navigation, true));
100100

101101

102-
var anchorTemplate = [
103-
'<span class="anchor-target" id="<%= id %>"></span>',
104-
'<a href="#<%= id %>" name="<%= id %>" class="anchor glyphicon glyphicon-link"></a>'
105-
].join('\n');
106-
102+
var anchorTemplate = '<a href="#<%= id %>" class="anchor glyphicon glyphicon-link"></a>';
107103

108104
// If an anchor template is specified in the options, use that instead.
109105
if (anchorOpts && anchorOpts.template) {
@@ -115,14 +111,10 @@ module.exports = function navigationPlugin(params, callback) {
115111
var $e = $(e);
116112
var id = $e.attr('id');
117113

118-
// Anchor template
119114
var anchor = template(anchorTemplate, {
120115
id: id
121116
});
122117
$(this).prepend(anchor);
123-
124-
// Adjust heading
125-
// $(this).removeAttr('id').addClass('docs-heading');
126118
$(this).addClass('docs-heading');
127119

128120
// if ($(this).prev().children().hasClass('source-link')) {

0 commit comments

Comments
 (0)