Variable Slide Timeout with jQuery Cycle 2
Asked Answered
E

1

5

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);
    }
});
Ectype answered 7/3, 2013 at 13:0 Comment(0)
E
10

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

Engender answered 7/3, 2013 at 16:36 Comment(3)
How does this work if you're defining options programmatically? Thanks for the great plugin btw, served me well for years.Pali
Thanks! Already tried many sliders (Slick, Owl..) but this is the first one to have this option :)Deherrera
2018 and this plugin still saving my life :')Canzona

© 2022 - 2024 — McMap. All rights reserved.