Using nivoSlider, how to determine the current slide image or index?

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 // 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);
+3
source share
1 answer

I did this with this method ...

var index = $(".nivo-controlNav .active").attr('rel')
+9
source

All Articles