Experiments in buildinig a mobile friendly table of contents

My current focus is on the mobile web. Everything I do need should be to help developers “get” mobile. With this in mind, I was skiming html5rocks on my nexus, and I was struck by the fact that I could not see any content on the first page. Not good.
There are a couple of things that we need to fix on HTML5Rocks when it comes to mobile. Today I am going to focus on the Table of Contents.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

<p>My current focus is on the mobile web. Everything I do need should be to help developers "get" mobile. With this in mind, I was skiming <a href="http://html5rocks.com">html5rocks</a> on my nexus, and I was struck by the fact that I could not see any content on the first page. Not good.</p> <p>There are a couple of things that <a href="https://github.com/html5rocks/www.html5rocks.com/issues/392">we</a> <a href="https://github.com/html5rocks/www.html5rocks.com/issues/390">need</a> <a href="https://github.com/html5rocks/www.html5rocks.com/issues/386">to</a> <a href="https://github.com/html5rocks/www.html5rocks.com/issues/384">fix</a> on HTML5Rocks when it comes to mobile. Today I am going to focus on the Table of Contents.</p> <p>The Table of Contents (ToC), depending on the article can be 1/2 a screen in height to 3 screens in height. However you look at the it, you have to scroll to be able to start reading the content. The Table of Contents is also rooted at the top of the document, which on mobile means that I have to scroll all the way to the top to be able to navigate around or understand the structure. Argh.</p> <p>Just have a look at one of the current articles. Yes the header is too large, but even this small ToC is blocking us from reading the content.</p> <figure> <img src="https://paul.kinlan.me/images/tocbad.png"> </figure> <p>I am working off the idea that if we can get the user to the content quicker, we will improve our read-time, reduce our bounce-rate and create an all-round better experience for developers who read the content we produce.</p> <p>There are some constraints though:</p> <ol> <li>ToC help you navigate around the page so they need to be visible to the user on page load</li> <li>Ideally they should always be visible, or easily accessible so you can quickly jump to the parts you need</li> <li>Due to constraints on the screen size, they should get out of the way as quickly as possible</li> <li>There should be no rendered-html differences between the mobile and "desktop" versions</li> <li>If possible use no JS.</li> </ol> <p>With all these in mind I have created my first experiemental ToC. I call it the "Bottom ToC".</p> <p>The Bottom ToC is simply a Table of Contents anchored to the bottom of the viewport. When the reader wants to get access to the page structure they simple tap the "ToC" area, it expands into view (whilst keeping them at the same point in their document) letting them select their next reading point. To dismiss the ToC the user can simply clicks back in the main document.</p> <p>Bottom ToC in its natural state:</p> <figure> <img src="https://paul.kinlan.me/images/tocbetter-collapsed.png"> </figure> <p>Bottom Toc expanded:</p> <figure> <img src="https://paul.kinlan.me/images/tocbetter.png"> </figure> <p>It's not perfect, but I thought it was interesting enough to document.</p> <p>So, how is it built?</p> <p>It was a pretty simple build in the end, it required no JavaScript and no changes to the rendered HTML. It uses a combination of <code>position: fixed</code> and the <code>:active</code> pseudo class.</p> <p>Our ToC is structured as a nested set of <ul> elements inside a <nav> element - pretty much how every menu is structured.</p> <pre><code><nav class="outline toc"> <h3>Table of Contents</h3> <ul> <li><a href="#toc-introduction">Introduction</a></li> <li><a href="#toc-topic-sounds">Creating the sounds</a></li> <li><a href="#toc-topic-sound">Engine sound</a> <ul> <li><a href="#toc-topic-looks-like">Looks like this</a></li> <li><a href="#toc-topic-go">Give it a go</a></li> </ul> </li> <li><a href="#toc-topic-sync">Getting the sync</a></li> </nav> </code></pre> <p>The CSS is simple too. To make it anchor to the bottom of the screen and open when the user clicks on it we do as follows:</p> <pre><code>.outline.toc { position: fixed; bottom: 0; left: 0; right: 0; height: 1em; overflow: auto; } .outline.toc:active { height: 5em; } </code></pre> <p>That's it. The important bits are the position: fixed, which takes the element out of the natural flow of the document and anchors it to a defined area in the viewport - in our case the bottom of the viewport. We used the <code>:active</code> psuedo class to manage the opening and closing of the table of contents.</p> <p><code>:active</code> is interesting on mobile as it is normally used to style an element with a id that matches the string in the document fragment of the URL (the bit after the #). This is often the case if you click on an anchor that points to an area inside the same document. On mobile browsers such as Safari and Chrome the <code>:active</code> class is also set when you press on any element, which leads to this effect. The really nice thing is that when you click back in the main article, the active element changes thus hiding the menu again.</p> <p>There are still a couple of isses to resolve so it is not the perfect solution. For example, when the user scrolls up or down in the ToC and reaches one of the extremities the scroll event gets passed through to the parent document.</p> <p>All in all, I think this is a neat little solution.</p>


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2013-06-13T00:00:00+00:00) Experiments in buildinig a mobile friendly table of contents. Retrieved from https://www.scien.cx/2013/06/13/experiments-in-buildinig-a-mobile-friendly-table-of-contents/

MLA
" » Experiments in buildinig a mobile friendly table of contents." Paul Kinlan | Sciencx - Thursday June 13, 2013, https://www.scien.cx/2013/06/13/experiments-in-buildinig-a-mobile-friendly-table-of-contents/
HARVARD
Paul Kinlan | Sciencx Thursday June 13, 2013 » Experiments in buildinig a mobile friendly table of contents., viewed ,<https://www.scien.cx/2013/06/13/experiments-in-buildinig-a-mobile-friendly-table-of-contents/>
VANCOUVER
Paul Kinlan | Sciencx - » Experiments in buildinig a mobile friendly table of contents. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2013/06/13/experiments-in-buildinig-a-mobile-friendly-table-of-contents/
CHICAGO
" » Experiments in buildinig a mobile friendly table of contents." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2013/06/13/experiments-in-buildinig-a-mobile-friendly-table-of-contents/
IEEE
" » Experiments in buildinig a mobile friendly table of contents." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2013/06/13/experiments-in-buildinig-a-mobile-friendly-table-of-contents/. [Accessed: ]
rf:citation
» Experiments in buildinig a mobile friendly table of contents | Paul Kinlan | Sciencx | https://www.scien.cx/2013/06/13/experiments-in-buildinig-a-mobile-friendly-table-of-contents/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.