Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to move flexslider to last slide

I have a flexslider object that's working perfectly. However I have an anchor on the page that needs to move the carousel to the last slide. Also the slide number can vary, so targeting a specific index value won't satisfy the requirements.

I have no trouble moving to specific indexes, as such (moves to first index position):

$('.flexslider').data("flexslider").flexAnimate(0);

I imagine there's some type of keyword, or perhaps an equation but I haven't found a reliable resource. Any thoughts?

like image 530
Travis Hall Avatar asked Dec 29 '25 16:12

Travis Hall


2 Answers

I think you were close to the answer. You can get the index of any concerned element in a collection/selector by .index() function.

Now, let's say you have ul of class .slides containing several li.

For getting the index of last li:

var index = $('.slides li').index($('.slides li:last'));

now since you've got the index of the desired slide, you can pass this index into flexslider to activate or show that slide:

$('.flexslider').data("flexslider").flexAnimate(index);

You can see that by default the slider begins from the last slide. Hope this helps

Further, you can use this into a click handler

Update: There was an issue with slide which doesn't allow manual sliding unless the next or prev links are clicked for the slider. The possible fix which I found is:

var lastSlide = $('.slides li').index($('.slides li:last'));
$("a.specs").click(function () {    
    flex.flexslider('next'); // This is the trick. 
    flex.flexslider(lastSlide)
});

Demo: http://jsfiddle.net/lotusgodkk/n9JUc/21/

like image 137
K K Avatar answered Jan 01 '26 08:01

K K


If you bypass the .flexslider helper function, then you can override the internal checker.

$('.flexslider').data("flexslider").flexAnimate(index, true, true);

The third parameter is the override parameter. It basically forces flexslider to animate to that slide even it doesn't pass the internal check of the canAdvance check.

This is necessary if you want to fade the animation instead of sliding. K K's work around doesn't work with the fade animation.

like image 27
Frank Robert Anderson Avatar answered Jan 01 '26 09:01

Frank Robert Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!