Search code examples
javascriptjquerycyclehtml-listsslidingdrawer

Cycle between li drawers - jquery


I've got a set of li drawers that when you click on each one it expands. But I dont want it to be interact-able I want this to cycle, expanding the next li drawer every 5 seconds for example. Also, the number of li drawers isnt fixed to 3. I want it to still cycle through all even if i add more li drawers to it. Hope that makes sense.

Here is my jsfiddle: http://jsfiddle.net/7WApV/

I've tried having a go at this myself using setInterval and .next().slideDown() but wasnt getting anwyhere. Can anyone help? Thanks!


Solution

  • Try this:

    var bam = $('H2.drawer-handle'),
        count = 0;
    window.setInterval(function() {
        if (count <= 1) {
            count++;
        } else {
            count = 0;
        }
        var item = $('H2.drawer-handle').get(count);
        $(item).click();
    }, 1500);
    

    Example: http://jsfiddle.net/7WApV/1/