Skip to content
Snippets Groups Projects
Commit 956b66bb authored by Sean Madsen's avatar Sean Madsen
Browse files

Improving auto scroll of nav to only scroll when necessary. Fully fixes #21

parent d7bc8cbd
Branches
No related tags found
No related merge requests found
// Automatically scroll the navigation menu to the active element
// https://github.com/civicrm/civicrm-dev-docs/issues/21
$('.wy-nav-side')
.scrollTop(
$('li.toctree-l1.current').offset().top -
$('.wy-nav-side').offset().top -
80
);
$.fn.isFullyWithinViewport = function(){
var viewport = {};
viewport.top = $(window).scrollTop();
viewport.bottom = viewport.top + $(window).height();
var bounds = {};
bounds.top = this.offset().top;
bounds.bottom = bounds.top + this.outerHeight();
return ( ! (
(bounds.top <= viewport.top) ||
(bounds.bottom >= viewport.bottom)
) );
};
if( !$('li.toctree-l1.current').isFullyWithinViewport() ) {
$('.wy-nav-side')
.scrollTop(
$('li.toctree-l1.current').offset().top -
$('.wy-nav-side').offset().top -
60
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment