2

每次移动后如何显示(在 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);
  }
});

谢谢你的帮助...

4

1 回答 1

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);
}
于 2014-08-11T20:38:12.563 回答