Skip to content

Instantly share code, notes, and snippets.

@gabrieleromanato
Created October 28, 2013 09:02
Show Gist options
  • Save gabrieleromanato/7193529 to your computer and use it in GitHub Desktop.
Save gabrieleromanato/7193529 to your computer and use it in GitHub Desktop.
Easy Backstretch update: added preload
<script type="text/javascript">
jQuery(document).ready(function($) {
var images = [];
<?php foreach($easy_backstretch_images as $image => $data): ?>
images.push('<?php echo $data['file_url']; ?>');
<?php endforeach; ?>
var index = 0;
var backstretchSettings = { fade: <?php echo $easy_backstretch_settings['fade']; ?>, duration:<?php echo $easy_backstretch_settings['duration'];?>};
var len = images.length;
var totalDuration = (backstretchSettings.fade + backstretchSettings.duration);
var timer = null;
var preload = function() {
for( var i = 0; i < images.length; ++i ) {
var img = document.createElement( 'img' );
var src = images[i];
img.src = src;
}
};
var rotate = function() {
$('<?php echo $easy_backstretch_settings["div"]; ?>').backstretch(images[0], backstretchSettings);
timer = setInterval(function() {
index++;
if(index == len) {
index = 0;
}
$('<?php echo $easy_backstretch_settings["div"]; ?>').backstretch(images[index], backstretchSettings);
}, totalDuration);
};
$.when( preload() ).done(
rotate() );
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment