I successfully implemented this feature using a CSS class and a small snippet of JavaScript to activate the class.
The concept revolves around comparing the position of the element with the current scroll of the viewport.
For a demonstration, you can visit my CodePen example: http://codepen.io/giacomofurlan/pen/hcfkE
To delve deeper into the specifics, check out my extended explanation here:
Here is the key part - the JavaScript controller (identifying nav#menu
as our sticky menu):
(function ($) {
"use strict";
var menuPosition = function () {
var nav = $("nav#menu"),
height = nav.height(),
windowHeight = $(window).height();
if ($(window).scrollTop() > (windowHeight - height)) {
nav.addClass('fixed');
} else {
nav.removeClass('fixed');
}
};
menuPosition();
$(document).scroll(menuPosition);
}(jQuery));
Additionally, here is the accompanying CSS class:
.fixed {
position: fixed;
top: 0px;
}