J K
J K

Reputation: 505

jQuery slider start position

Some time ago I copied some slider code from some website. Can't find where is it now. The code is:

slides.min.jquery.js

$(function(){
    $('#slides').slides({
        preload: true,
        play: 12000,
        pause: 8000,
        hoverPause: true,
        generatePagination: false
    });
});

The slider works well. But, my problem now is, I want the slider to start at random slide position. For example, it can randomly start at slide 5, or slide 3, or slide 4; on each refresh.

Any help?

Upvotes: 0

Views: 1184

Answers (2)

Kevin Bowersox
Kevin Bowersox

Reputation: 94469

It appears your using slide.js the documentation specifies you can set the start slide by including the start property in the settings.

$(function(){
    var EXCLUSIVE_UPPER_BOUNDS = 5; //adjust for your app
    $('#slides').slides({
        preload: true,
        play: 12000,
        pause: 8000,
        hoverPause: true,
        generatePagination: false,
        start: Math.floor(Math.random()* EXCLUSIVE_UPPER_BOUNDS)
    });
});

Upvotes: 2

DhruvPathak
DhruvPathak

Reputation: 43245

Echo the slider slides in random order on every page load. Or you DOM manipulation to sort them in random order and place them again in their parent container. Then use your javascript to initiate the slider.

eg.:

<div id='slides' >
 <img src='image_a' />
 <img src='image_b' />
 <img src='image_c' />
 <img src='image_d' />
</div>

It is trivial to convert this into :

<div id='slides' >
 <img src='image_b' />
 <img src='image_a' />
 <img src='image_d' />
 <img src='image_c' />
</div>

Using DOM manipulation or shuffling at backend script.

Upvotes: 0

Related Questions