1
0
mirror of https://github.com/bitwarden/help synced 2025-12-06 00:03:30 +00:00

update url with hash while maintain smooth scroll (#297)

This commit is contained in:
David Choi
2020-11-16 12:42:52 -08:00
committed by GitHub
parent a2342ddc5e
commit c8bf637ecd
5 changed files with 25 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
<nav class="navbar navbar-expand-lg fixed-top navbar-dark"> <nav class="navbar navbar-expand-lg fixed-top navbar-dark" id="main-nav">
<a class="navbar-brand" href="/" onclick="gaEvent('Nav Logo')"> <a class="navbar-brand" href="/" onclick="gaEvent('Nav Logo')">
<i class="fa fa-shield"></i> <i class="fa fa-shield"></i>
<span class="hidden-sm"><strong>bit</strong>warden</span> <span class="hidden-sm"><strong>bit</strong>warden</span>

View File

@@ -12,7 +12,7 @@
</div> </div>
</header> </header>
<nav class="search-navbar navbar navbar-light bg-light"> <nav class="search-navbar navbar navbar-light bg-light">
<a class="search-sidebar-toggle d-block d-md-none py-2 px-3" type="button" data-toggle="collapse" data-target="#bd-docs-nav" aria-controls="menu" aria-expanded="true" aria-label="Toggle sidebar"> <a class="search-sidebar-toggle d-block d-md-none py-2 px-3" type="button" data-toggle="collapse" data-target="#bd-docs-nav" aria-controls="menu" aria-expanded="false" aria-label="Toggle sidebar">
Contents Contents
<i class="fa fa-chevron-down ml-1"></i> <i class="fa fa-chevron-down ml-1"></i>
</a> </a>

View File

@@ -1,6 +1,6 @@
{% assign sorted_articles = site.articles | sort: 'order' %} {% assign sorted_articles = site.articles | sort: 'order' %}
<nav class="bd-links collapse show" id="bd-docs-nav" aria-label="Main navigation"> <nav class="bd-links collapse" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item d-none d-sm-none d-md-block"> <div class="bd-toc-item d-none d-sm-none d-md-block">
<a class="bd-toc-link" href="/help/"> <a class="bd-toc-link" href="/help/">
Help Center Help Center

View File

@@ -9,12 +9,12 @@ body {
padding-top: $navbar-height; padding-top: $navbar-height;
} }
// :target::before { :target::before {
// content: ''; content: '';
// display: block; display: block;
// height: $navbar-height + 5px; height: $navbar-height + 5px;
// margin-top: -$navbar-height + 5px; margin-top: -$navbar-height + 5px;
// } }
a { a {
color: $link-color; color: $link-color;

View File

@@ -69,31 +69,25 @@ $(function () {
}); });
// smooth scrolling // smooth scrolling
$('a[href*="#"]').click(function(e) { $('a[href^="#"]').click(function () {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var target = $(this.hash);
var target = $(this.hash); var hash = this.hash;
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) { if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
e.preventDefault(); if (target.length == 0) target = $('html');
const NAVBAR_HEIGHT = 62 + 5;
$('html, body').animate({ $('html, body').animate({
scrollTop: target.offset().top - NAVBAR_HEIGHT scrollTop: target.offset().top - $('#main-nav').outerHeight()
}, 500, function() { }, 500, function () {
var $target = $(target); if (history.pushState) {
$target.focus(); history.pushState(null, null, hash);
if ($target.is(":focus")) { } else {
return false; location.hash = hash;
} else {
$target.attr('tabindex','-1');
$target.focus();
};
});
} }
} });
return false;
}); });
// collapse // collapse sidebar
// $('.collapse').collapse() // $('#bd-docs-nav').toggleClass('show', $(window).width() > 1024);
}); });