Skip to content

Instantly share code, notes, and snippets.

@flexseth
Last active August 13, 2016 16:04
Show Gist options
  • Save flexseth/def61d5f81743314a690 to your computer and use it in GitHub Desktop.
Save flexseth/def61d5f81743314a690 to your computer and use it in GitHub Desktop.
Home page parallax in Genesis Sample child theme (parallax header)
/**
* This file adds the Home Page to the Parallax Pro Theme.
*
* @author Brad Dalton
* @package Parallax
* @subpackage Customizations
*/
add_action( 'genesis_meta', 'parallax_home_genesis_meta' );
/**
* Add widget support for homepage. If no widgets active, display the default loop.
*
*/
function parallax_home_genesis_meta() {
if ( is_active_sidebar( 'home-section-1' ) ) {
//* Enqueue parallax script
add_action( 'wp_enqueue_scripts', 'parallax_enqueue_parallax_script' );
function parallax_enqueue_parallax_script() {
if ( ! wp_is_mobile() ) {
wp_enqueue_script( 'parallax-script', get_bloginfo( 'stylesheet_directory' ) . '/js/parallax.js', array( 'jquery' ), '1.0.0' );
}
}
//* Add parallax-home body class
add_filter( 'body_class', 'parallax_body_class' );
function parallax_body_class( $classes ) {
$classes[] = 'parallax-home';
return $classes;
}
//* Add homepage widgets
add_action( 'genesis_loop', 'parallax_homepage_widget' );
}
}
}
//* Add markup for homepage widget
function parallax_homepage_widget() {
genesis_widget_area( 'home-parallax', array(
'before' => '<div class="home-odd home-parallax widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
genesis();
jQuery(function( $ ){
// Enable parallax and fade effects on homepage sections
$(window).scroll(function(){
scrolltop = $(window).scrollTop()
scrollwindow = scrolltop + $(window).height();
$(".home-parallax").css("backgroundPosition", "0px " + -(scrolltop/6) + "px");
});
});
.home-parallax {
background-attachment: fixed;
background-color: #fff;
background-position: 0px 0px;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
}
@media only screen and (max-width: 1139px) {
.home-parallax {
background-attachment: scroll;
background-position: top;
-webkit-background-size: auto;
-moz-background-size: auto;
background-size: auto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment