mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-09-27 13:38:07 +00:00
add sidenav scrollspy
This commit is contained in:
@@ -64,17 +64,18 @@
|
|||||||
|
|
||||||
{{ with .Params.Location }}
|
{{ with .Params.Location }}
|
||||||
<div class="p-h-sm p-v-xs"><i class="material-icons">location_on</i> {{ . }}</div>
|
<div class="p-h-sm p-v-xs"><i class="material-icons">location_on</i> {{ . }}</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ template "_internal/pagination.html" . }}
|
{{ template "_internal/pagination.html" . }}
|
||||||
{{ partial "breadcrumbs.html" . }}
|
{{ partial "breadcrumbs.html" . }}
|
||||||
</article>
|
</article>
|
||||||
<aside class="col-sm-3 col-xs-12 unstyled">
|
<div class="offset-watch invisible"></div>
|
||||||
|
<aside class="col-sm-3 col-xs-12 unstyled toc-container">
|
||||||
<h4 class="m-b-0">On this page</h4>
|
<h4 class="m-b-0">On this page</h4>
|
||||||
{{ .TableOfContents }}
|
{{ .TableOfContents }}
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -36,7 +36,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{{ partial "breadcrumbs.html" . }}
|
{{ partial "breadcrumbs.html" . }}
|
||||||
</article>
|
</article>
|
||||||
<aside class="col-sm-3 col-xs-12 unstyled">
|
<div class="offset-watch invisible"></div>
|
||||||
|
<aside class="col-sm-3 col-xs-12 unstyled toc-container">
|
||||||
<h4 class="m-b-0">On this page</h4>
|
<h4 class="m-b-0">On this page</h4>
|
||||||
{{ .TableOfContents }}
|
{{ .TableOfContents }}
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -209,6 +209,53 @@ const bootstrapNav = function () {
|
|||||||
$('.tree-nav').removeClass('invisible');
|
$('.tree-nav').removeClass('invisible');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bootstrapScrollSpy = function () {
|
||||||
|
|
||||||
|
$(window).scroll(scrollHandler)
|
||||||
|
|
||||||
|
function scrollHandler() {
|
||||||
|
let $class = 'sticky';
|
||||||
|
let $el = $('.toc-container');
|
||||||
|
let $watch = $('.offset-watch');
|
||||||
|
let scrollTop = $(window).scrollTop();
|
||||||
|
let elementOffset = $watch.offset().top;
|
||||||
|
let distance = (elementOffset - scrollTop);
|
||||||
|
let mainContentHeaders = $('.main-content').find(':header:visible');
|
||||||
|
let opts = {
|
||||||
|
height: $el.outerHeight(),
|
||||||
|
width: $el.outerWidth(),
|
||||||
|
left: $el.offset().left,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(scrollTop, $(window).height())
|
||||||
|
for (var i = 0; i <= mainContentHeaders.length - 1; i++) {
|
||||||
|
var $mainContentHeadersEl = $(`#${mainContentHeaders[i].id}`);
|
||||||
|
var hTop = $mainContentHeadersEl.offset().top;
|
||||||
|
|
||||||
|
if (hTop - scrollTop >= 0) {
|
||||||
|
mainContentHeaders.each( ( i, a ) => {
|
||||||
|
$('#TableOfContents').find(`a[href$=${a.id}]`).removeClass('active');
|
||||||
|
});
|
||||||
|
$('#TableOfContents').find(`a[href$=${mainContentHeaders[i].id}]`).addClass('active');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (distance <= 0) {
|
||||||
|
|
||||||
|
$el.css(opts);
|
||||||
|
$el.addClass($class)
|
||||||
|
|
||||||
|
} else if (distance >= 0){
|
||||||
|
|
||||||
|
$el.removeClass($class)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
scrollHandler();
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
bootstrapNav();
|
bootstrapNav();
|
||||||
@@ -216,4 +263,5 @@ $(document).ready(() => {
|
|||||||
bootstrapModals();
|
bootstrapModals();
|
||||||
bootstrapSorts();
|
bootstrapSorts();
|
||||||
bootstrapSlider();
|
bootstrapSlider();
|
||||||
|
bootstrapScrollSpy();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,3 +59,14 @@
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sticky {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#TableOfContents {
|
||||||
|
.active {
|
||||||
|
background-color: $accent-two;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user