OWL Carousel afterMove获得img alt

时间:2014-04-22 07:25:19

标签: javascript jquery carousel alt owl-carousel

如何在每次移动后显示(在div中)图像alt? 我试试这个,但它没有工作(我总是第一个alt)

<div id="owlSlider" class="owl-carousel owl-theme">
      <div class="item"><img src="lg/img_1.jpg" alt="Image 1" class="img-responsive"></div>
      <div class="item"><img src="lg/img_2.jpg" alt="Image 2" class="img-responsive"></div>
      <div class="item"><img src="lg/img_3.jpg" alt="Image 3" class="img-responsive"></div>
</div>
<div><p id="legend" style="font-size:1.4em">&nbsp;</p></div>



$("#owlSlider").owlCarousel({
  navigation : false, 
  pagination: true,
  slideSpeed : 300,
  paginationSpeed : 400,
  singleItem:true,
  autoPlay:true,
  transitionStyle : 'fade',
  rewindNav: true,
  afterMove : function (elem) {
        var leg = elem.find('img').attr('alt');
        //console.log(elem);
        $('#legend').html(leg);
  }
});

感谢您的帮助......

1 个答案:

答案 0 :(得分:6)

试一试:

..
afterMove : function (elem) {
  var current = this.currentItem;
  var alt = elem.find(".item").eq(current).find("img").attr('alt');
  console.log('Imagem current is ' + alt);
}