Jquery Nivo Slider set delay time for each slide

Douglas Cottrell picture Douglas Cottrell · Nov 9, 2012 · Viewed 12.3k times · Source

We are using a special system that allows our users to set a delay between slides and whether or not the image contains a link. We were using mootools for the slideshow but wish to update to nivoSlider.

A php script exports the following as per our old system requirements

var data = {
'0225201274127_1.jpg': {delay:4000},
'0225201274417_4.jpg': {delay:3000},
'0225201274624_9.jpg': {delay:5000},
'0225201274607_8.jpg': {delay:3000},
'0225201274456_6.jpg': {delay:6000},
'0225201274521_7.jpg': {delay:7000},
'0225201274435_5.jpg': {delay:3000},
'0225201274338_2.jpg': {delay:2000},
'0225201274647_10.jpg': {delay:1000},
'0225201274359_3.jpg': {delay:6000},
'0225201274707_11.jpg': {delay:4000}
};

I am simply looking for a way to set the delays above to the individual images in the slideshow.

If needed I can reconfigure the output. We have been trying different methods all day without success.

Answer

vts picture vts · Dec 27, 2012

I'm using an array with 'afterLoad' and it works good.

  var delays = [4000,3000,5000,3000]; //your delay array

    function pageLoad() {
        $(function () {
            $('#slider').nivoSlider({
                pauseTime: 50000,
                directionNav: true,
                afterChange: function () { setDelay() },
                afterLoad: function () { setDelay() },
                controlNav: true,
                pauseOnHover: false
            });
        });
    }

    function setDelay() {
        var currentSlide = $('#slider').data("nivo:vars").currentSlide;
        setTimeout(function () {
            $('#slider').find('a.nivo-nextNav').click()
        }, delays[currentSlide]);

    }

hope this helps. The rest of your html is standar nivo layout