Board Logo

Randomizing the order of the scrolling items
tigra - 1/3/2006 at 07:09 PM

Below function will shuffle the scroller items:


function random_items (a_source) {
var n_index, a_items = [];
while (a_source.length) {
n_index = Math.ceil(Math.random() * a_source.length) - 1;
a_items[a_items.length] = a_source[n_index];
a_source[n_index] = a_source[a_source.length - 1];
a_source.length = a_source.length - 1;
return a_items;

It can be used like this:


new TScroll_init (Tscr_LOOK, Tscr_BEHAVE, random_items(Tscr_ITEMS));

yaya20 - 3/16/2006 at 05:38 PM

I've been trying to find a way to do this and what you pose is much simpler than what I was trying to do...

In what file do I need to put the random function? And where/how do I call it correctly?

tigra - 3/16/2006 at 10:49 PM

The function can be inserted in .js file or inside the <script> tag anywhere obove the place where it is first called. See the call example in the initial post.

yaya20 - 3/17/2006 at 03:09 AM

Thanks. After some work I got it functioning.

Back to forum: