The current method I use just increments the index value in the event afterChange, but it breaks when the user moves backward. How to determine what the current image index is?
(function($){ $(function(){
var i = 0
var swapColor = function(){
var index = i++ % $("#slider img").length
var color = $("#slider img").eq(index).data('color')
$(".nivo-caption, .nivo-html-caption").css({backgroundColor: color})
}
$('#slider').nivoSlider({
afterLoad: swapColor,
beforeChange: swapColor
});
}) })(jQuery);
source
share