Last active
January 26, 2017 23:44
-
-
Save neilgee/a6f8017e532fb0c2ea1a to your computer and use it in GitHub Desktop.
Agency Pro - Multiple background Images
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
<?php | |
//* Enqueue Backstretch script and prepare images for loading | |
add_action( 'wp_enqueue_scripts', 'agency_enqueue_backstretch_scripts' ); | |
function agency_enqueue_backstretch_scripts() { | |
// $image = get_option( 'agency-backstretch-image', sprintf( '%s/images/bg.jpg', get_stylesheet_directory_uri() ) ); | |
//* Load scripts only if custom backstretch image is being used | |
//if ( ! empty( $image ) ) { | |
wp_enqueue_script( 'agency-pro-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' ); | |
wp_enqueue_script( 'agency-pro-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agency-pro-backstretch' ), '1.0.0' ); | |
//wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', $image ) ) ); | |
// } | |
} |
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(document).ready(function($) { | |
// Create an array of images that you'd like to use | |
var images = [ | |
'/wp-content/themes/dmand/images/bg.jpg', | |
'/wp-content/themes/dmand/images/bg1.jpg', | |
'/wp-content/themes/dmand/images/bg2.jpg', | |
'/wp-content/themes/dmand/images/bg3.jpg', | |
]; | |
// Get a random number between 0 and the number of images | |
var randomNumber = Math.floor( Math.random() * images.length ); | |
// Use the random number to load a random image | |
$("body.home").backstretch([ | |
images[randomNumber], | |
],{ | |
duration:3000, | |
fade:750, | |
}); | |
}); | |
//Source - https://github.com/srobbin/jquery-backstretch/issues/135 |
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(document).ready(function($) { | |
$("body.home").backstretch([ | |
'/wp-content/themes/dmand/images/bg.jpg', | |
'/wp-content/themes/mytheme/images/bg1.jpg', | |
'/wp-content/themes/mytheme/images/bg2.jpg', | |
'/wp-content/themes/mytheme/images/bg3.jpg', | |
],{ | |
duration:3000, | |
fade:750, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can only get this to work on the homepage of the 411-theme , get white pages else where. What could be the issue thanks