最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using nivoSlider, How can I determine the current slide image or index? - Stack Overflow

programmeradmin3浏览0评论

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);

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);
Share Improve this question asked May 22, 2012 at 12:37 Billy MoonBilly Moon 58.6k27 gold badges148 silver badges244 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

I did it using this method...

var index = $(".nivo-controlNav .active").attr('rel')
发布评论

评论列表(0)

  1. 暂无评论