ajmalafif
1/27/2013 - 2:55 PM

[wp - forked] - Flexslider to Change Background Image

[wp - forked] - Flexslider to Change Background Image

$(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;');
        }
    });
});