View Full Version : Random 1st Image in Content Slider

12-24-2012, 06:09 AM
Hi There,
While I have visited here often and found some wonderful goodies here, I have never had the need to post . . . so this is my first!
How can I change the code, so that the first image in a 4 slide slider is randomly selected instead of it always being the same first slide?

12-24-2012, 06:38 AM
That depends upon how those slides appear in the code. One way or another though you could get them into an array. With some sliders they already are in an array. Once you have them in an array, you can shuffle that array. Here's an array shuffling routine:

array_name.sort(function(){return 0.5 - Math.random();});

where array_name is the name of the array. This should of course be done before the slider starts, probably before it's fully initialized, perhaps before anything is done for the slider.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

12-24-2012, 07:24 AM
Thanks John,
I just used the 2.4 slider version code here. I didn't see an array in either pieces I downloaded from this site. I basically want to modify the code here, its not an independant project.

12-24-2012, 03:11 PM
Modified function

var persistedpage=this.getCookie("fcspersist"+setting.id) || 1
if (typeof(setting.randomstart)=='number'){
var urlselectedpage=this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index
this.settingcaches[setting.id]=setting //cache "setting" object
setting.currentpage=urlselectedpage || ((this.enablepersist)? persistedpage : 1)
setting.revealtype="on"+(setting.revealtype || "click")
setting.onChange=setting.onChange || function(){}
if (setting.contentsource[0]=="inline")
if (setting.contentsource[0]=="ajax")

new option

id: "slider1", //id of main slider DIV
contentsource: ["inline", ""], //Valid values: ["inline", ""] or ["ajax", "path_to_file"]
toc: "#increment", //Valid values: "#increment", "markup", ["label1", "label2", etc]
nextprev: ["Previous", "Next"], //labels for "prev" and "next" links. Set to "" to hide.
revealtype: "click", //Behavior of pagination links to reveal the slides: "click" or "mouseover"
enablefade: [true, 0.2], //[true/false, fadedegree]
autorotate: [false, 3000], //[true/false, pausetime]
randomstart:3, // the number of content DIVS
onChange: function(previndex, curindex){ //event handler fired whenever script changes slide
//previndex holds index of last slide viewed b4 current (1=1st slide, 2nd=2nd etc)
//curindex holds index of currently shown slide (1=1st slide, 2nd=2nd etc)

12-24-2012, 03:51 PM
Thanks Vic,
That works exactly the way I wanted!!