javascript - OWL Carousel afterMove 获取 img alt

标签 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);
  }
});

感谢您的帮助...

最佳答案

试一试:

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

关于javascript - OWL Carousel afterMove 获取 img alt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23213176/

相关文章:

php - 只允许从特定页面访问链接?

javascript - 在 OL 中的页面加载/刷新时显示本地存储

twitter-bootstrap - Bootstrap 轮播可以像这个网站那样发挥作用吗?

html - 如何在右上角正确放置 Bootstrap 指示器?

javascript - 如何更改显示选项的 HTML5 数据列表背景颜色

javascript - react : Flow: Import a local js file - cannot resolve issue module

javascript - Jquery用于保留选择选项中的选定值

php - 如何从 javascript 发出 ajax 请求以获取核心 php 功能

jquery - 为什么简单的 fn.extend 不起作用?

jquery - Bootstrap 轮播无法正常工作