Skip to content

Instantly share code, notes, and snippets.

@srikat
Created December 16, 2013 15:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save srikat/7988642 to your computer and use it in GitHub Desktop.
Save srikat/7988642 to your computer and use it in GitHub Desktop.
Fading away an element when scrolling down and fading it back when scrolling up in WordPress. http://sridharkatakam.com/fade-away-element-scrolling-fade-back-scrolling-wordpress/
add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' );
function sk_enqueue_scripts() {
if ( !is_home() || !is_front_page() )
return;
wp_enqueue_script( 'scrollTo', get_stylesheet_directory_uri() . '/js/jquery.scrollTo.min.js', array( 'jquery' ), '1.4.5-beta', true );
wp_enqueue_script( 'home', get_stylesheet_directory_uri() . '/js/home.js', array( 'scrollTo' ), '', true );
}
jQuery(function( $ ){
function fade_home_top() {
if ( $(window).width() > 800 ) {
window_scroll = $(this).scrollTop();
$("#home_bkgrd_image").css({
'opacity' : 1-(window_scroll/300)
});
}
}
$(window).scroll(function() { fade_home_top(); });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment