<nav class="navbar fixed-top navbar-expand-lg scrolling-navbar navbar-primary">
<ul class="navbar-skiplinks">
<li>
<a href="#section-1 ">Skip to content</a>
</li>
</ul>
<div class="container">
<a class="navbar-brand" href="/">
<span class="sr-only">Hoofdpagina</span>
<div class="navbar-brand-container">
<img src="/v6.0.0/img/beeldmerklabelwit.svg" class="logo-labeled" alt="Logo Nijmegen">
<img src="/v6.0.0/img/beeldmerkwit.svg" class="logo" aria-hidden="true" alt="">
</div>
</a>
<div class="collapse navbar-collapse" id="navbar-collapse">
</div>
</div>
</nav>
Based on the fixed top version from MDB:
https://mdbootstrap.com/components/navbar/#basic-example
Read more about skiplinks here
Aside from the markup, some extra actions are needed.
body
element to not risk having content under the navbar which should be visible by default.To set an active menu item, underneath HTML markup for a navigation item can be used where a class active
is added to the active menu item and as and extra addition regarding accessibility the “span” can be used.
<li class="nav-item active">
<a href="#" class="nav-link">Menu <span class="sr-only">(huidig)</span></a>
</li>
Include the script below to enable automatic closing of the menu on a mobile when:
When using the navbar to scroll to content on the same page make sure to add the class smooth-scroll
to the navbar-nav
element.
For the autocomplete search a real-time feed is provided by Pandosearch. This uses a combination of search suggestions and direct hits. To use this search functionality, JavaScript code is required before the closing “body” tag.
Please note: The track=false
query parameter in the suggestUrl
should be removed for production
<script>
// Please note that the track=false should be removed on production!
var suggestUrl = 'https://public.pandosearch.com/nijmegen.nl/suggest?size=5&track=false&q=';
var autocomplete = new nijmegen.Autocomplete();
$(document).ready(function () {
autocomplete.init(getAutocompleteResults, '?q={query}');
});
function getAutocompleteResults(query, callback) {
$.get(suggestUrl + query, function (rawResults) {
// Get suggestions from raw search results
var suggestions = rawResults.suggestions
.map(function (suggestion) {
return {
title: suggestion.text,
url: '?q=' + suggestion.text,
class: 'search'
};
});
// Get hits from raw search results
var hits = Array.isArray(rawResults.hits)
? rawResults.hits
.map(function (hit) {
return {
title: hit.title,
url: hit.url
};
})
: [];
var result = [];
if (hits.length) {
result = result.concat({ header: 'Zoekresultaten:' }, hits);
}
if (suggestions.length) {
result = result.concat({ header: 'Zoeksuggesties:' }, suggestions);
}
callback(result);
});
}
</script>
When the container of the menu has the class nijmegen-smooth-scroll
the page will scroll smoothly to the corresponding section.
For this to work you need to add a hash to the url, smooth scrolling will take place when:
#section-1
will scroll smoothly to a element with the id: section-1
Using
section here. For an example of the search results, have a look at the search results template.