-
-
Save flexseth/def61d5f81743314a690 to your computer and use it in GitHub Desktop.
Home page parallax in Genesis Sample child theme (parallax header)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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