PDA

View Full Version : Help with Pausing up-down Scroller



indijanac
02-21-2010, 01:50 AM
Link of script is: http://www.dynamicdrive.com/dynamicindex2/crosstick.htm

I need to make it that messages will go random, is that possible?! What need to be changed?!

jscheuer1
02-21-2010, 08:28 AM
Well, there are at least three ways to look at that. If you mean each time the page loads a random order for the messages will be set, that's easy. Do it like so (addition highlighted):


<script type="text/javascript">

/*Example message arrays for the two demo scrollers*/

var pausecontent=new Array()
pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'

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

var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www. . . .

This may be done for one or more (if you have more than one) array of contents. Simply run the randomizing command after each array declaration you want to randomize, using that array's name, as shown in the example.

If however you want to have a random message shown each time the message changes, that's a little misleading because it would lead to duplicate messages being shown one after another at times. Random means random. Any message, including that just shown, could follow any message. A subroutine could be developed to prevent that, essentially shuffling the array after removing the current message. But you would still occasionally get the same message following soon after itself. So, as tempting in theory as it might seem, I'd advise against that approach.

The third method would be to shuffle after each time a full cycle of messages had been shown. This could still result in duplicate messages following one after the other. Only this time, though a less likely (rarer) occurrence, I'm not sure how if at all that could be prevented. So again I wouldn't recommend it.

indijanac
02-21-2010, 04:12 PM
yeah thats what i wanted, everytime when page is loaded to show random messages. Just one more question:

if i add 10 pausecontent messages, i must change something in:
pausecontent.sort(function() {return 0.5 - Math.random();});

or not?!

jscheuer1
02-21-2010, 06:32 PM
Not. It will work for any length array.

indijanac
02-21-2010, 06:38 PM
Thank you very much.