jqueryjquery-cycle

Variable Slide Timeout with jQuery Cycle 2


I'm trying to setup a slideshow to use data attributes for setting the timeout on each slide. This works for jQuery Cycle, but not for jQuery Cycle 2. I think I might be using the wrong function, but didn't find anything similar in the Cycle 2 docs?

HTML:

<div id="slides">
    <img src="img1.jpg" data-duration="1000" />
    <img src="img2.jpg" data-duration="2000" />
    <img src="img3.jpg" data-duration="3000" />
</div>

JS:

$('#slides').cycle({
    fx: 'fadeout',
    speed: 250,
    timeoutFn: function(currElement, nextElement, opts, isForward) { 
        return parseInt($(currElement).attr('data-duration'), 10);
    }
});

Solution

  • Cycle2 supports that directly. Use data-cycle-timeout attributes on the slides instead of data-duration.