Most examples come from the Sitefinity project and some of the classes, ids and html structure of them, can be strange, but it can easily be transformed and used everywhere and as needed for everyone.
function stickyNavigation() {
window.onscroll = function (e) {
var y = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop,
navId = document.getElementById("navigation"),
navOffsetTop = navId.offsetTop;
if (y >= navOffsetTop) {
navId.className = 'stick';
} else {
navId.className = '';
}
}
}