erik-krogh / SudoSlider

The most versatile jQuery content slider
36 stars 24 forks source link

Possible to Start on specific slide but the rest are Randomized? #26

Closed syberknight closed 9 years ago

syberknight commented 9 years ago

i'm just reading thru the documentation on your website, considering using SudoSlider. i see there's an option for "startSlide" - which, as i understand it, allows me to pick which slide the show starts on at every page load; and i see i can randomize the Effects... but i'm not seeing where i can have the slides themselves be shown in a random order.

ideally for me, i'm looking for a slider that will let me pick which slide to start on for each page load, and then ALSO will auto pick the order of the rest of the slides at random.

doable? if so, how? THANK YOU!!!

webbiesdk commented 9 years ago

Doable, yes. But not as something SudoSlider does.

What you can do is randomize the slides, before SudoSlider even see them (assuming you don't use Ajax).

If you slider has id="slider" and your slides are contained in div's then just paste the following before SudoSlider is initialized:

$.each(shuffle($("#slider > div")), function (index, elem) {
    $("#slider").append(elem);
});

If you use ul and li tags, insert the following instead.

$.each(shuffle($("#slider > ul > li")), function (index, elem) {
    $("#slider").append(elem);
});
syberknight commented 9 years ago

hhmmm, i'll give that a try tonight & see how it goes. but before i do, one more Q... will this pre-randomization of slides still allow SudoSlider to start with the specific slide i choose in its options? Thanks again!

webbiesdk commented 9 years ago

First of all, oops. You need to include the below function for the above to work.

// Mutates and returns the array.
function shuffle(array) {
    for (var j, x, i = array.length; i; j = parseInt(Math.random() * i), x = array[--i], array[i] = array[j], array[j] = x) {
    }
    return array;
}

Secondly, all the slides will be shuffled before SudoSlider knows they exist, so no matter what you set startSlide to, it will start at a random slide.

syberknight commented 9 years ago

oh. well, then this won't work for me. it's required that a particular slide be the first. it's requested the rest are randomized, but, i guess we can't all have what we want ;-)

thank you very much, tho, for your time & extra code here. much appreciated.