使用nivoSlider,如何确定当前的幻灯片图像或索引

Using nivoSlider, How can I determine the current slide image or index?

本文关键字:幻灯片 图像 索引 nivoSlider 何确定 使用      更新时间:2023-09-26

我当前使用的方法只是在事件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')