Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The current method I use simply increments an index value on afterChange event, but this breaks when the user navigates backwards. How can I 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);
like image 208
Billy Moon Avatar asked Dec 01 '25 05:12

Billy Moon


1 Answers

I did it using this method...

var index = $(".nivo-controlNav .active").attr('rel')
like image 74
Billy Moon Avatar answered Dec 03 '25 17:12

Billy Moon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!