如何使用 jquery 循环更改图像持有者的背景颜色

how to change the background color of the holder of an image using jquery cycle

我正在为我网站上的图片使用 jQuery.cycle.all.js。我想将图像的背景更改为图像 changes/cycles。很明显我想用 id flash 更改 div 的背景。如何做到这一点,任何想法?

这是 jsfiddle:http://jsfiddle.net/nixiechen/3ndpfnys/

这里是 javascript:

$('.holder').cycle({
    timeout:2000        
});

/*pause-play buttons*/
$('.pause').on('click',function() {         
    $(this).removeClass('on');
    $('.play').addClass('on');
    $('.holder').cycle('pause'); 
});
$('.play').on('click',function() {          
    $(this).removeClass('on');      
    $('.pause').addClass('on');     
    $('.holder').cycle('resume'); 
});

HTML

<div id="flash">
    <div class="wrapper">
        <div class="btns">
            <a href="#" class="play" id="">&nbsp;</a>
            <a href="#" class="pause on" id="">&nbsp;</a>
        </div>
        <div class="holder">
            <img src="../images/01.jpg" alt="image"/>
            <img src="../images/02.jpg" alt="image"/>
            <img src="../images/03.jpg" alt="image"/>
            <img src="../images/04.jpg" alt="image"/>
        </div>
    </div>      
</div>

CSS

#flash { overflow: hidden; position: relative; height: 350px; background: #0a0f2c; }
#flash .wrapper { position: relative; height: 350px; z-index: 1; }
#flash .btns { position: absolute; overflow: hidden; top: 175px; left: 5px; z-index: 10000; }
#flash .btns a { float: left; width: 21px; height: 21px; margin: 0px 5px 0px 0px; text-decoration: none; }
#flash .btns a.play { display: block; background: url(../images/btn/btn_play_off.png) 0 0 no-repeat; }
#flash .btns a.play.on { background: url(../images/btn/btn_play_on.png) no-repeat; }
#flash .btns a.pause { background: url(../images/btn/btn_pause_off.png) 0 0 no-repeat; }
#flash .btns a.pause.on { background: url(../images/btn/btn_pause_on.png) no-repeat; }
#flash .holder { position: absolute; left: -150px; }
#flash .blue { background: #0a0f2c; }
#flash .brown { background: #3b1e16; }
#flash .black { background: #000; }

更新了 jsfiddle link

您可以将 background-color 添加到 cycle before function 中的 #flash

Jsfiddle

var color = 154235;
$('.holder').cycle({
    timeout: 2000,
    before: function (currSlideElement, nextSlideElement) {
        $('#flash').css({
            'background-color': '#' + color
        });
        color += 20;
    }
});