PDA

View Full Version : Random 1st Image in Content Slider



Mikelli
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?

jscheuer1
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.

Mikelli
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.

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


init:function(setting){
var persistedpage=this.getCookie("fcspersist"+setting.id) || 1
if (typeof(setting.randomstart)=='number'){
persistedpage=Math.floor(Math.random()*setting.randomstart+1);
}
var urlselectedpage=this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index
this.settingcaches[setting.id]=setting //cache "setting" object
setting.contentdivs=[]
setting.toclinks=[]
setting.topzindex=0
setting.currentpage=urlselectedpage || ((this.enablepersist)? persistedpage : 1)
setting.prevpage=setting.currentpage
setting.revealtype="on"+(setting.revealtype || "click")
setting.curopacity=0
setting.onChange=setting.onChange || function(){}
if (setting.contentsource[0]=="inline")
this.buildpaginate(setting)
if (setting.contentsource[0]=="ajax")
this.ajaxconnect(setting)
}


new option



featuredcontentslider.init({
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)
}
})

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