Results 1 to 5 of 5

Thread: Random 1st Image in Content Slider

  1. #1
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random 1st Image in Content Slider

    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?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Modified function

    Code:
    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

    Code:
    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)
    	}
    })
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  5. #5
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Vic,
    That works exactly the way I wanted!!

Similar Threads

  1. Content Slider + IE Image Issue
    By ayesay in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-24-2010, 04:45 PM
  2. Resolved Featured Content Slider random image?
    By cool263 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 08-04-2009, 07:14 PM
  3. Ajax tab content with random image
    By Goodboy in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 05-01-2009, 07:46 AM
  4. Featured Content Slider v2.4 - one slider with several paginate-slider
    By beathead in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 08-05-2008, 09:05 AM
  5. Random Content Order script - non-repeating random content
    By doomeyes in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-06-2008, 09:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •