iOS7 Style List Navigator
If you're looking for a sleek mobile interface, check out my iOS7 style list navigator. I found Apple's solution to be very intuitive, so we borrowed it.
This code assumes that you won't need to scroll the body, as many smartphone designs allow fixed headers and footers for Android versions less than 4 without any issues.
A quick note: this code is fresh and hasn't been thoroughly tested yet.
CHECK OUT DEMO AND CODE
CSS (excerpt)
#scrolling {
padding-top: 44px;
overflow: scroll;
-webkit-overflow-scroll: touch;
height: 100%;
}
.menu {
position: fixed;
right: 0;
font-size: 12px;
text-align: center;
display: inline-block;
z-index: 2;
top: 58px;
}
.list .divider {
position: -webkit-sticky; /* stops label when reaching header */
top: 44px;
}
HTML (excerpt)
<div id="scrolling">
<ul class="menu">
<li><a href="#a">A</a></li>
<li><a href="#b">B</a></li>
<li><a href="#c">C</a></li>
<!-- more list items -->
</ul>
<ul class="list">
<li class="divider" id="a">A</li>
<li><a href="#">Amelia Webster</a></li>
<li><a href="#">Andrew Wilkinson</a></li>
<!-- more list items -->
Javascript (zepto/jquery)
$(function() {
$(window).on("touchstart touchmove mouseover click", ".menu a", function(e) {
e.preventDefault();
clearInterval(t);
var steps = 25;
var padding = 68;
var target = $( $(this).attr("href") ).next("li");
if ( target.length > 0 ) {
var scroller = $("#scrolling")[0];
var step = parseInt((target[0].offsetTop - padding - scroller.scrollTop)/steps);
var stepno = 0;
setInterval( function() {
if ( stepno++ <= steps ) {
scroller.scrollTop += step;
} else {
clearInterval(t)
}
}, 20);
};
});
});
The code checks link validity before attempting to scroll. Feel free to adjust the padding value to suit your needs.
Keep in mind that we are targeting the first element after the specified target due to Safari's behavior with sticky positioning.
This code utilizes jQuery/Zepto selectors for simplicity and readability, but these libraries aren't necessary. With a bit more effort, you can achieve the same result without dependencies.
http://codepen.io/frapporti/pen/GtaLD