Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Last active February 20, 2017 09:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/4586395 to your computer and use it in GitHub Desktop.
Save wpsmith/4586395 to your computer and use it in GitHub Desktop.
Add Nagging Menu to WordPress Site
<?php
add_action( 'init', 'wps_register_nagging_script' );
/**
* Register Nagging script
*
* @uses CHILD_THEME_VERSION set this via wp_get_theme()->Version
* @link https://gist.github.com/4477270 Sets Child Theme Constants via wp_get_theme()
* @link https://gist.github.com/4083811 For jQuery alternative to be placed in footer
*/
function wps_nagging_script() {
$suffix = ( WP_DEBUG || SCRIPT_DEBUG ) ? '.js' : '.min.js';
wp_enqueue_script(
'nagging-menu',
get_stylesheet_directory_uri() . '/js/nagging-menu' . $suffix,
array( 'jquery' ),
CHILD_THEME_VERSION, // I set this via wp_get_theme()->Version, @link https://gist.github.com/4477270
true
);
}
<?php
add_action( 'init', 'wps_register_nagging_script' );
/**
* Register Nagging script
*
* @uses CHILD_THEME_VERSION set this via wp_get_theme()->Version
* @link https://gist.github.com/4477270 Sets Child Theme Constants via wp_get_theme()
* @link https://gist.github.com/4083811 For jQuery alternative to be placed in footer
*/
function wps_register_nagging_script() {
$suffix = ( WP_DEBUG || SCRIPT_DEBUG ) ? '.js' : '.min.js';
wp_register_script(
'nagging-menu',
get_stylesheet_directory_uri() . '/js/nagging-menu' . $suffix,
array( 'jquery' ),
CHILD_THEME_VERSION, // I set this via wp_get_theme()->Version, @link https://gist.github.com/4477270
true
);
}
add_action( 'wp_enqueue_scripts', 'wps_nagging_script' );
/**
* Enqueue Nagging script if on home/archive page
*/
function wps_nagging_script() {
if ( is_home() || is_front_page() || is_archive() || is_tax() )
wp_enqueue_script( 'nagging-menu' );
}
jQuery(document).ready(function($) {
"use strict";
// Change #nav to #subnav for Genesis default Secondary Menu
var menu = $('#nav').find('.menu'),
pos = menu.offset();
// Add Default class
menu.addClass('default');
$(window).scroll(function(){
if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){
menu.fadeOut('fast', function(){
$(this).removeClass('default').addClass('fixed').fadeIn('fast');
});
} else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
menu.fadeOut('fast', function(){
$(this).removeClass('fixed').addClass('default').fadeIn('fast');
});
}
});
});
jQuery(document).ready(function(e){"use strict";var t=e("#nav").find(".menu"),n=t.offset();t.addClass("default");e(window).scroll(function(){if(e(this).scrollTop()>n.top+t.height()&&t.hasClass("default")){t.fadeOut("fast",function(){e(this).removeClass("default").addClass("fixed").fadeIn("fast")})}else if(e(this).scrollTop()<=n.top&&t.hasClass("fixed")){t.fadeOut("fast",function(){e(this).removeClass("fixed").addClass("default").fadeIn("fast")})}})})
#nav .fixed,
#subnav .fixed,
.fixed {
background: rgb(0,0,0); /* Fallback */
background: rgba(0,0,0,0.97); /* All modern browsers */
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#00000000', endColorstr='#00000000'); /* IE */
-webkit-box-shadow: 0 0 40px #222;
-moz-box-shadow: 0 0 40px #222;
box-shadow: 0 0 40px #222;
left: 0;
top: 0;
position: fixed;
width: 100%;
}
#nav .default,
#subnav .default,
.default {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment