Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active October 6, 2016 19:17
Show Gist options
  • Save srikat/8681944 to your computer and use it in GitHub Desktop.
Save srikat/8681944 to your computer and use it in GitHub Desktop.
Using Waypoints Sticky Elements to fix elements to top of page upon scrolling in WordPress. http://sridharkatakam.com/using-waypoints-sticky-elements-fix-elements-top-page-upon-scrolling-wordpress/
add_action( 'wp_enqueue_scripts', 'stick_elements' );
function stick_elements() {
wp_enqueue_script( 'waypoints', get_stylesheet_directory_uri() . '/js/waypoints.min.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'waypoints-sticky', get_stylesheet_directory_uri() .'/js/waypoints-sticky.min.js' , array( 'waypoints' ), '1.0.0' );
wp_enqueue_script( 'waypoints-sticky-init', get_stylesheet_directory_uri() .'/js/waypoints-sticky-init.js' , array( 'waypoints-sticky' ), '1.0.0' );
}
/* Sticky Tagline section at viewport widths 600px and above in Minimum Pro
---------------------------------------------------------------------------- */
@media only screen and (min-width: 600px) {
.minimum .site-tagline.stuck {
position: fixed;
width: 100%;
top: 62px;
margin-top: 0;
}
.admin-bar .site-tagline.stuck {
top: 90px;
}
.site-tagline.stuck {
position: fixed;
width: 100%;
top: 62px;
margin-top: 0;
}
}
/* Sticky Primary Nav at viewport widths 600px and above
----------------------------------------------------------- */
@media only screen and (min-width: 600px) {
.nav-primary.stuck {
position: fixed;
width: 100%;
top: 0;
}
.admin-bar .nav-primary.stuck {
top: 28px;
}
}
jQuery(document).ready(function($) {
$('.nav-primary').waypoint('sticky');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment