Skip to content

Instantly share code, notes, and snippets.

@mannieschumpert
Created March 19, 2013 13:52
Show Gist options
  • Save mannieschumpert/5196271 to your computer and use it in GitHub Desktop.
Save mannieschumpert/5196271 to your computer and use it in GitHub Desktop.
Refactored version of my menu-toggling script.
(function($) { // Use a wrapper since WordPress loads jQuery in noconflict mode
// Menu Toggling
$(document).ready(function(){
var sidebar = $(".sidebar");
$(".toggle").click(function(){
var $this = $(this);
if ($this.hasClass('open') ){sidebar.toggleClass("active");}
$(".sidenav").toggleClass("inactive");
setTimeout(function() {
$this.addClass("hide");
$this.siblings().removeClass("hide");
if ($this.hasClass('close') ){sidebar.toggleClass("active");}
}, 500);
return false;
});
});
// Make menu sticky if scrolled
$(document).scroll(function() {
var scrollpoint = 176; // Set point at which nav becomes sticky
var sidebar = $('.sidebar');
var sitenav = sidebar.find('.sitenav');
var top = $(document).scrollTop();
if (top > scrollpoint) {
sidebar.css({'position' : 'fixed', 'top' : '16px'});
sitenav.slideDown(); // Reveal main site page nav (hidden by default)
}
if (top < scrollpoint) {
sidebar.removeAttr('style');
sitenav.slideUp(); // Re-hide main site page nav
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment