我当前使用的方法只是在事件afterChange
递增索引值,但是当用户向后导航时,这会中断。如何确定当前图像索引是什么?
(function($){ $(function(){
var i = 0
var swapColor = function(){
var index = i++ % $("#slider img").length // gets the calculated index according to hom many times the slider has swapped slides
var color = $("#slider img").eq(index).data('color')
$(".nivo-caption, .nivo-html-caption").css({backgroundColor: color})
}
$('#slider').nivoSlider({
afterLoad: swapColor,
beforeChange: swapColor
});
}) })(jQuery);
我用这种方法做到了......
var index = $(".nivo-controlNav .active").attr('rel')