简体   繁体   English

jQuery Cycle2:如何通过幻灯片编号获取幻灯片

[英]jquery cycle2: how to get a slide by its slide number

I am using cycle 2 ( http://jquery.malsup.com/cycle2/ ) to create a carousel, and I am having trouble figuring out how to access slides by there "slide number". 我正在使用第2周期( http://jquery.malsup.com/cycle2/ )创建轮播,并且在弄清楚如何通过“幻灯片编号”来访问幻灯片时遇到了麻烦。

I can loop through the slide array using cycle.API and find the slide numbers 我可以使用cycle.API遍历幻灯片数组并找到幻灯片编号

$('#respo-slider').on('cycle-post-initialize', function(e, opts) {
    for(var i=0; i < opts.slideCount; i++){
       var slide_opt = $('#respo-slider').data('cycle.API').getSlideOpts(i);
   var slide_num = slide_opt["slideNum"];
   }
});

but I can't find anywhere in the api how to get the element by its slide using jquery (so I can then edit the attributes of the slide element). 但是我在api的任何地方都找不到如何使用jquery通过其幻灯片获取元素的方法(因此我可以随后编辑slide元素的属性)。

What I am looking for is something along the lines of: 我正在寻找的是类似以下内容的东西:

$('#respo-slider').getSlide(slide_num);

I have spent far to long trying to figure this out and I am stumped. 我花了很长时间试图弄清楚这一点,但我很沮丧。 Can anyone out there enlighten me? 外面有人可以启发我吗?

So like... 就像...

$('#respo-slider').children('div').index(slide_num);

Assuming the slides are in div elements. 假设幻灯片位于div元素中。

The slides are already in order, and their index should be the same as the slide number. 幻灯片已经整理好了,它们的索引应该与幻灯片编号相同。

Once the carousel initializes, it's going to duplicate the slides a bunch of times, so you want make your changes before it initializes, not after; 轮播初始化后,它将重复复制幻灯片很多次,因此您需要在初始化之前而不是之后进行更改。 since that would give you multiples of each slide. 因为那样会给您每张幻灯片的倍数。

By making the changes before initialization, the changes should be cloned when the carousel effect is created. 通过在初始化之前进行更改,应在创建轮播效果时克隆更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM