如何在每次移动后显示(在 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"> </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/