Skip to content

Instantly share code, notes, and snippets.

@incidunt
Forked from srikat/functions.php
Created April 29, 2019 03:24
Show Gist options
  • Save incidunt/7de37a1ab3be89c106f8d9f2de626499 to your computer and use it in GitHub Desktop.
Save incidunt/7de37a1ab3be89c106f8d9f2de626499 to your computer and use it in GitHub Desktop.
Fading in last sidebar widget as it is scrolled to and making it fixed in Genesis. http://sridharkatakam.com/fade-last-sidebar-widget-scrolled-make-fixed-genesis/
add_action( 'wp_enqueue_scripts', 'enqueue_sticky_last_widget' );
function enqueue_sticky_last_widget() {
wp_enqueue_style( 'animate', get_stylesheet_directory_uri() . '/css/animate.min.css' );
wp_enqueue_script( 'waypoints', get_stylesheet_directory_uri() . '/js/waypoints.min.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'waypoints-init', get_stylesheet_directory_uri() .'/js/waypoints-init.js' , array( 'jquery', 'waypoints' ), '1.0.0' );
wp_enqueue_script( 'jquery-sticky', get_stylesheet_directory_uri() .'/js/jquery.sticky.js' , array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'jquery-sticky-init', get_stylesheet_directory_uri() .'/js/jquery.sticky.init.js' , array( 'jquery-sticky' ), '1.0.0' );
}
jQuery(document).ready(function($) {
$(".sidebar-primary .widget:last-child").sticky({getWidthFrom: ".sidebar-primary .sticky-wrapper", className: "stuck"});
});
/*
Fading in last sidebar widget as it is scrolled to and making it fixed
-----------------------------------------------------------------------------*/
.sidebar-primary .widget:last-child {
filter: alpha(opacity=0);
opacity: 0;
/*animation-duration: 1.5s;*/
}
.admin-bar .stuck .widget {
top: 28px !important;
/*top: 68px !important;*/
}
jQuery(function($) {
$('.sidebar-primary .widget:last-child').waypoint(function(direction) {
if (direction == 'up') {
$(this).removeClass( 'fadeIn' ).addClass( 'fadeOut' );
}
else {
$(this).removeClass('fadeOut').addClass( 'animated fadeIn' );
}
},
{
offset: '50%',
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment