2

This fiddle works as intended, when the last li has a class on, the first li gets a class of first.

I am trying to use the same principle with the jQuery Cycle plugin. If you have a look at this fiddle you will see that the cycle plugin adds a class of activeSlide to the active slide. I have put some code in fidle which I thought would handle it but it looks as though maybe I have my logic wrong?

ak85
  • 4,154
  • 18
  • 68
  • 113

1 Answers1

3

You're only checking for the activeSlide class once, when the document is loaded. Wrap your logic inside a click handler on the rows and it should work:

$('#nav li').click(function() {
    if( $('.activeSlide').is('li:last-child') ) {
        $('li:first').addClass('first');
    }
    else {
        $('li:first').removeClass('first');
    }
});

Click here for live example

What if I want to check for the active slide on each interval of the cycle?

You can add a callback to the after option and run the logic there as well. Check out all the available options for more information.

Click here for a live example

Hubro
  • 56,214
  • 69
  • 228
  • 381
  • +1 as adding your code to the original fiddle works. The fiddle you linked though doesn't inlcud that code. – Nope Aug 01 '12 at 11:58
  • I understand now thanks. I have updated your answer to have the now working fiddle included. – ak85 Aug 01 '12 at 12:03
  • @FrançoisWahl: That was peculiar, I was sure I pressed save. I just updated to the working Fiddle myself anyway :) – Hubro Aug 01 '12 at 12:04
  • Looking at this one again @Codemonkey what would happen if there was a timeout in the cycle like in http://jsfiddle.net/aaronk85/Y2muS/39/ is there a way to handle it automatically (without the click?) or as you said earlier will this mean activeSlide will only be checked once? – ak85 Aug 01 '12 at 22:17
  • @ak85: You put the logic into a function and add it to the `after` callback option. I have updated my answer to include this information. – Hubro Aug 01 '12 at 23:52
  • thanks @Codemonkey I have seen this page for but I was looking at the jQuery documentation rather than the cycle documentation for the answer. Thanks! – ak85 Aug 02 '12 at 01:59