3

我正在寻找一种在( ) 中显示img标题和alt标签的方法。div.image-caption

到目前为止,这是我的代码:

    owl.on('changed.owl.carousel', function(event) {

        var comment = $(this).find('img').attr('alt');
        var title = $(this).find('img').attr('title');
        if(comment) $('#desktop .image-caption').html('<h4>'+title+'</h4><p>'+comment+'</p>');

    })      

有任何想法吗?谢谢!

4

2 回答 2

2

您可以translated.owl.carousel为此使用事件

这是一个工作小提琴

owl.on('translated.owl.carousel', function(event) {
     var comment = $(this).find('.active').find('img').attr('alt');
    var title = $(this).find('.active').find('img').attr('title');
    if(comment) $('.image-caption').html('<h4>'+title+'</h4><p>'+comment+'</p>');
});

更新:

稍微改进了代码并添加了在轮播加载时更新图像标题的功能。

小提琴

于 2015-04-21T07:31:58.990 回答
0

这有效:

var comment = $(this).find('.active').find('img').attr('alt');
var title = $(this).find('.active').find('img').attr('title');
if(comment) $('.image-caption').html('<h4>'+title+'</h4><p>'+comment+'</p>');

试试看:https ://jsfiddle.net/wx0ovpzh/49/

于 2015-04-20T21:39:36.353 回答