[英]Flexslider count the slides on each slider
I am using Flexslider to create several sliders on a page. 我正在使用Flexslider在页面上创建多个滑块。 It's a Wordpress so the posts are created dynamically.
这是一个Wordpress,因此帖子是动态创建的。 I'm counting the slides with the callback function and this line:
我正在用回调函数和以下行来计数幻灯片:
$('.promo-image-counter').text(slider.count);
but of course it changes the text on all of the image counters (all of the sliders show the number of slides from the last slider), I need to count the slides on each slider individually. 但是,当然,它会更改所有图像计数器上的文本(所有滑块均显示最后一个滑块中的幻灯片数量),我需要分别计算每个滑块上的幻灯片。
My code so far: 到目前为止,我的代码:
$(".slider-promos").flexslider({
animation: "slide",
controlNav:false,
touch:true,
start: function(slider){
$('body').removeClass('loading');
$('.promo-image-counter').text(slider.count);
$('.slides li img').show();
}
});
I have correctly count the slides on each slider with this code: 我已经使用此代码正确计算了每个滑块上的幻灯片:
$(".slider-promos").flexslider({
animation: "slide",
controlNav:false,
touch:true,
slideshow: false,
start: function(slider){
$('.slides li img').show();
$('body').removeClass('loading');
$(slider).find($(".promo-image-counter")).text(slider.count);
}
});
Needed to use 需要使用
$(slider).find($(".promo-image-counter")).text(slider.count);
instead of 代替
$(this).find($('.promo-image-counter')).text(slider.count);
I need to count the slides on each slider individually.
我需要分别计算每个滑块上的幻灯片。
You already do this, your failure is that you overriding the ".promo-image-counter" content with the count of the latest created slider instance. 您已经这样做了,您的失败是您用最新创建的滑块实例的计数覆盖了“ .promo-image-counter”内容。 As you assume, you want this behaviour for each slider.
如您所料,您希望每个滑块具有这种行为。 You can reach this by selecting ".promo-image-counter"-element for each slider, something like this:
您可以通过为每个滑块选择“ .promo-image-counter”元素来实现此目的,如下所示:
$('.slider1.promo-image-counter').text(slider.count);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.