Forked from dcatkins40/Flexslider to Change Background Image
Last active
December 11, 2015 19:28
-
-
Save ajmalafif/4648714 to your computer and use it in GitHub Desktop.
[wp - forked] - Flexslider to Change Background Image
This file contains hidden or 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
$(document).ready(function() { | |
var imgArr = new Array ( | |
<?php | |
$total = count(get_field('field')); | |
$count = 1; | |
while(the_repeater_field('field', $pagenumber)): ?> | |
'<?php the_sub_field('sub_field'); ?>'<?php if($count < $total){echo ',';} $count++; ?> | |
<?php endwhile; ?> | |
); | |
var n = 0; | |
function preload(arrayOfImages) { | |
$(arrayOfImages).each(function(){ | |
$('<img/>')[0].src = this; | |
}); | |
} | |
preload(imgArr); | |
$('.flexslider').flexslider({ | |
start: function(slider) { | |
$('#container').attr('style', 'background-image: url(' + imgArr[n] + '); background-position: center; background-repeat: no repeat; background-size: cover;'); | |
}, | |
before: function(slider) { | |
}, | |
after: function(slider) { | |
n = slider.currentSlide; | |
$('#container').attr('style', 'background-image: url(' + imgArr[n] + '); background-position: center; background-repeat: no repeat; background-size: cover;'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment