admin管理员组

文章数量:1406924

How can i show (in the div) the image alt after each move ? I try this but it's not working (I get always the first 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);
  }
});

Thanks for your help...

How can i show (in the div) the image alt after each move ? I try this but it's not working (I get always the first 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);
  }
});

Thanks for your help...

Share Improve this question edited May 6, 2014 at 15:37 Joshua Taylor 86k9 gold badges162 silver badges364 bronze badges asked Apr 22, 2014 at 7:25 ChrisChris 4351 gold badge8 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Try it:

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

本文标签: javascriptOWL Carousel afterMove get img altStack Overflow