Created
June 19, 2015 19:22
-
-
Save killa-kyle/96f174ec4dbff1c739e0 to your computer and use it in GitHub Desktop.
sticky nav
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ================================= | |
=== STICKY NAV ==== | |
=================================== */ | |
$(document).ready(function() { | |
$('.main-navigation').onePageNav({ | |
scrollThreshold: 0.5, // Adjust if Navigation highlights too early or too late | |
filter: ':not(.external)', | |
changeHash: true | |
}); | |
$(".local-scroll").localScroll({ | |
target: "body", | |
duration: 1000, | |
offset: 0 | |
}); | |
}); | |
/* COLLAPSE NAVIGATION ON MOBILE AFTER CLICKING ON LINK - ADDED ON V1.5*/ | |
if (matchMedia('(max-width: 480px)').matches) { | |
$('.main-navigation a').on('click', function () { | |
$(".navbar-toggle").click(); | |
}); | |
} | |
/* NAVIGATION VISIBLE ON SCROLL */ | |
$(document).ready(function () { | |
mainNav(); | |
}); | |
$(window).scroll(function () { | |
mainNav(); | |
}); | |
var scrollState = 'scrolled'; | |
if (matchMedia('(min-width: 992px), (max-width: 767px)').matches) { | |
function mainNav() { | |
var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop; | |
if ((top > 40) && (scrollState === 'top')) { | |
$('.sticky-navigation').stop().animate({"top": '0'}); | |
scrollState = 'scrolled'; | |
} else if ((top <= 40) && (scrollState === 'scrolled')) { | |
$('.sticky-navigation').stop().animate({"top": '-60'}); | |
scrollState = 'top'; | |
} | |
} | |
} | |
if (matchMedia('(min-width: 768px) and (max-width: 991px)').matches) { | |
function mainNav() { | |
var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop; | |
if ((top > 40) && (scrollState === 'top')) { | |
$('.sticky-navigation').stop().animate({"top": '0'}); | |
scrollState = 'scrolled'; | |
} else if ((top <= 40) && (scrollState === 'scrolled')) { | |
$('.sticky-navigation').stop().animate({"top": '-120'}); | |
scrollState = 'top'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment