Jquery 猫头鹰转盘2-获取当前幻灯片的src
我有以下代码块。我所要做的就是在幻灯片中获取当前图像的src。它不工作,控制台中根本没有显示任何内容,尽管它很好 HTML:Jquery 猫头鹰转盘2-获取当前幻灯片的src,jquery,owl-carousel-2,Jquery,Owl Carousel 2,我有以下代码块。我所要做的就是在幻灯片中获取当前图像的src。它不工作,控制台中根本没有显示任何内容,尽管它很好 HTML: 代码不起作用的原因是没有为Owl转盘定义onChange回调 有关可用选项,请参见标题“回调”下的 如果您将其更新为使用“afterMove”,则在移动幻灯片后,它将正常工作 您可能还想考虑使用“后继”来启动、移动和更新,这取决于您的要求。 JS 编辑 在进一步阅读了OWLCarousel2的注释和文档中提供的链接之后,这里是一个使用OWLCarousel2的工作示例。看
代码不起作用的原因是没有为Owl转盘定义onChange回调 有关可用选项,请参见标题“回调”下的 如果您将其更新为使用“afterMove”,则在移动幻灯片后,它将正常工作
您可能还想考虑使用“后继”来启动、移动和更新,这取决于您的要求。
JS 编辑 在进一步阅读了OWLCarousel2的注释和文档中提供的链接之后,这里是一个使用OWLCarousel2的工作示例。看到这个了吗 与测试版中的任何内容一样,github的问题和答案可能很快就会过时。从owl转盘2站点的文档中找到了解决方案 HTML实际上,一旦change在没有函数的情况下工作(),我想函数就有问题了。如果我在onChange中运行一个警报或console.log,它就可以正常工作。我用的是猫头鹰旋转木马2。afterMove在我的原始代码块中使用,但也不起作用,onChange是我脚本所需的工具。@AndyHolmes-刚刚浏览了owl carousel 2站点上的文档,并使它为您工作。请看上面编辑的答案。非常感谢!!这解决了我的问题。这就是如何通过您的方法获得
项.index
。非常感谢。猫头鹰转盘2中既没有后置动作
也没有后置动作
。你应该删除这个作为最佳答案,以免混淆像我这样的掉队者…@LyndonJohnson-阅读整个问题,包括正确答案的编辑。
<div id="banner" class="owl-carousel">
<img src="template/banner-1.jpg" alt="">
<img src="template/banner-2.jpg" alt="">
<img src="template/banner-1.jpg" alt="">
<img src="template/banner-2.jpg" alt="">
</div>
var owl = $(".owl-carousel");
owl.owlCarousel({
loop: true,
autoplay: true,
items: 1,
animateOut: 'fadeOut',
onChange: function (elem) {
var current = this.currentItem;
var src = elem.find(".owl-item").eq(current).find("img").attr('src');
console.log('Image current is ' + src);
}
});
var owl = $(".owl-carousel");
owl.owlCarousel({
loop: true,
autoplay: true,
items: 1,
animateOut: 'fadeOut',
afterMove: function (elem) {
var current = this.currentItem;
var src = elem.find(".owl-item").eq(current).find("img").attr('src');
console.log('Image current is ' + src);
}
});
<div id="banner" class="owl-carousel">
<img src="http://www.live-on-the-edge.com/wp-content/uploads/2014/06/Sam-Tomkins-730x547.jpg" alt=""/>
<img src="http://static.guim.co.uk/sys-images/Sport/Pix/pictures/2009/6/11/1244720277422/Aussie-Rugby-League-001.jpg" alt=""/>
<img src="http://static.guim.co.uk/sys-images/Sport/Pix/pictures/2010/1/7/1262873655905/Rugby-referee-001.jpg" alt=""/>
<img src="http://static.guim.co.uk/sys-images/Sport/Pix/columnists/2011/3/3/1299187263691/football-league-premier-l-007.jpg" alt=""/>
</div>
var owl = $(".owl-carousel");
owl.owlCarousel({
loop: true,
autoplay: true,
items: 1,
animateOut: 'fadeOut'
});
// jQuery method on
owl.on('changed.owl.carousel',function(property){
var current = property.item.index;
var src = $(property.target).find(".owl-item").eq(current).find("img").attr('src');
console.log('Image current is ' + src);
});