By default, when you view the Glossary, the title and the quick-links to each letter will disappear as you scroll the page.
If you have a lot of glossary terms and you're linking to your glossary in your table of contents or navigation, you may want to keep the Glossary header visible while scrolling.
To add this functionality to your knowledge base, you'll create a snippet to store the code and then add that snippet to the Custom HTML:
- Go to Library > Snippets.
- Click the + New Snippet button.
- Give your snippet a Name (Sticky glossary header, in our example).
- Give your snippet a Description, like "Make the glossary header "sticky" so it's always visible as people scroll."
- Click the dropdown next to Snippet Content to select Code Editor.
- Copy the script below and paste it into the code editor.
<script> $(function(){ // Adjust the pathname listed below depending on your KB settings. It might be 'help/glossary', '/home/glossary' or '/docs/glossary' if(window.location.pathname == '/help/glossary') { if($('.ko-content-cntr').length > 0) var articleCont = $('.ko-content-cntr'); else var articleCont = $('.documentation-article'); var articleWidth = articleCont.width(); var navTop = $('.hg-header').outerHeight(true); var topDiv = $('<div/>', {class: "ko-glossary-topdiv"}); articleCont.prepend(topDiv); topDiv.append($('h1.page-header')).append($('div.glossary-jump-to')); var topOfJumpto = topDiv.offset().top; var jumptoHeight = topDiv.outerHeight(true); topDiv.affix({ offset: { top: topOfJumpto - navTop, } }); //add dynamic reusable styles $('<style>.ko-glossary-topdiv.affix{top:'+navTop+'px;width:'+articleWidth+'px;background:#fff;}.ko-glossary-topdiv.affix + .glossary-terms-wrapper{margin-top:'+jumptoHeight+'px}</style>').appendTo('head'); } }); </script> <style> /* Make sure that glossary header doesn't cover content when you jump to a letter */ .hg-glossary-page a:not([href]) { display: block; height: 200px; margin-top: -200px; visibility: hidden; } </style>
- The code is used for knowledge bases with /help/ in their URLs. If you are using 'home' or 'docs' instead, you'll need to update the window.location.pathname in line 4 based on your knowledge base's settings to
'/home/glossary'
or'/docs/glossary'
. - Click the Create button in the upper right. Here's what a completed snippet might look like:
- Once it confirms your snippet is created, copy the Merge Code Value ({{snippet.stickyGlossaryHeader}} in our example).
- Go to Settings > Style.
- Below the preview pane, click on Custom HTML and select Body from the dropdown.
- Paste the snippet merge code value into the bottom of the window.
- Click Save.
Your glossary's header should now stay at the top regardless of how far down your readers scroll.