Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active December 27, 2017 17:17
Show Gist options
  • Save srikat/8971980 to your computer and use it in GitHub Desktop.
Save srikat/8971980 to your computer and use it in GitHub Desktop.
Parallax animations in Genesis using Stellar.js. http://sridharkatakam.com/parallax-animations-genesis-using-stellar-js/
//* Enqueue Stellar on homepage
add_action( 'wp_enqueue_scripts', 'enqueue_stellar' );
function enqueue_stellar() {
if ( ! ( is_home() || is_front_page() ) )
return;
wp_enqueue_script( 'stellar', get_stylesheet_directory_uri() . '/js/jquery.stellar.min.js', array( 'jquery' ), '', true );
wp_enqueue_script( 'stellar-init', get_stylesheet_directory_uri() . '/js/jquery.stellar.init.js', array( 'stellar' ), '1.0.0', true );
}
//* Register Home Slider widget area
genesis_register_sidebar( array(
'id' => 'home-parallax-section',
'name' => __( 'Home Parallax Section', 'your-theme-slug' ),
'description' => __( 'This is the home parallax widget area.', 'your-theme-slug' ),
) );
//* Display Home Parallax Section below Header (+Nav)
add_action ( 'genesis_after_header', 'sk_parallax_section' );
function sk_parallax_section() {
if ( ! ( is_home() || is_front_page() ) )
return;
genesis_widget_area( 'home-parallax-section', array(
'before' => '<div id="home-parallax-section" class="parallax-section" data-stellar-background-ratio="0.5"><div class="wrap"',
'after' => '</div></div>',
) );
}
<div data-stellar-ratio="2" class="layered-image" id="layered-image-1"><img src="http://genesis.dev/wp-content/themes/genesis-sample/images/picjumbo.com_IMG_9870-150x150.jpg" /></div>
<div data-stellar-ratio="0.5" class="layered-image" id="layered-image-2"><img src="http://genesis.dev/wp-content/themes/genesis-sample/images/picjumbo.com_IMG_0398-100x100.jpg" /></div>
jQuery(document).ready(function($) {
$.stellar();
});
#home-parallax-section {
background-image: url('images/picjumbo.com_IMG_7925-1600x1050.jpg');
}
.parallax-section {
background-attachment: fixed;
background-position: 0px 0px;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
font-size: 28px;
padding: 190px 0 200px;
text-align: center;
color: #fff;
}
.parallax-section h4 {
font-size: 72px;
color: #fff;
text-transform: none;
}
#home-parallax-section {
position: relative;
overflow: hidden;
}
.layered-image {
position: absolute;
}
.layered-image img {
border-radius: 1000px;
-webkit-border-radius: 1000px;
-moz-border-radius: 1000px;
border: 2px solid #fff;
}
#layered-image-1 {
right: 10px;
top: 50%;
}
#layered-image-2 {
left: 20%;
top: 10%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment