473,509 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help to randomize slideshow in this script

Okay, first of all, I'm a complete noob, so go easy on me. I have this
code that works perfectly for me. The only thing I want to add is to
randomize the pictures/links that show up. Can anyone just tell me
where to add additional code to the following? BTW this is the only
code I could find that works in my Beta Blogger sidebar.
<a href="javascript:gotoshow()"><img border="0" width="300"
src="/OneMissedCall1.jpg" name="slide" height="150"/></a>
<script language="JavaScript1.1">
<!--

/*
JavaScript Image slideshow:
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScript here!
*/

var slideimages=new Array()
var slidelinks=new Array()
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}

function slideshowlinks(){
for (i=0;i<slideshowlinks.arguments.length;i++)
slidelinks[i]=slideshowlinks.arguments[i]
}

function gotoshow(){
if (!window.winslide||winslide.closed)
winslide=window.open(slidelinks[whichlink])
else
winslide.location=slidelinks[whichlink]
winslide.focus()
}

//-->
</script>

<a href="javascript:gotoshow()"><img border="0" width="300"
src="OneMissedCall1.jpg" name="slide" height="150"/></a>
<script>
<!--

//configure the paths of the images, plus corresponding target links
slideshowimages("/OneMissedCall1.jpg","/2LDK1.jpg","/TokyoZombie-001.jpg")
slideshowlinks("/one-missed-call.html","/2ldk.html","/tokyo-zombie.html")

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=4000

var whichlink=0
var whichimage=0
function slideit(){
if (!document.images)
return
document.images.slide.src=slideimages[whichimage].src
whichlink=whichimage
if (whichimage<slideimages.length-1)
whichimage++
else
whichimage=0
setTimeout("slideit()",slideshowspeed)
}
slideit()

//-->
</script>
Any help would be MUCH appreciated! Thank you.

Nov 11 '06 #1
6 2378
ASM
mrtaka79 a écrit :
Okay, first of all, I'm a complete noob, so go easy on me. I have this
code that works perfectly for me. The only thing I want to add is to
randomize the pictures/links that show up. Can anyone just tell me
where to add additional code to the following? BTW this is the only
code I could find that works in my Beta Blogger sidebar.
(snip)
<a href="javascript:gotoshow()"><img border="0" width="300"
src="OneMissedCall1.jpg" name="slide" height="150"/></a>
<script>
No,

<script type="text/javascript">
<!--

//configure the paths of the images, plus corresponding target links
slideshowimages("/OneMissedCall1.jpg","/2LDK1.jpg","/TokyoZombie-001.jpg")
slideshowlinks("/one-missed-call.html","/2ldk.html","/tokyo-zombie.html")

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=4000
// randomize
function radomSlideShow() {
var L = slideshowimages.length;
var R = new Array();
var k = 0;
while(k<L) {
var n = Math.floor(Math.random()*L)
var ok = true;
for(var i=0; i<R.length; i++)
if(R[i] == n) ok = false;
if(ok) { R[R.length] = n; k++ }
}
return R;
}

var randomOrder = radomSlideShow();
var whichlink=0
var whichimage=0
function slideit(){
if (!document.images)
return
whichlink=randomOrder[whichimage];
document.images.slide.src=slideimages[whichlink].src
if (whichimage<slideimages.length-1)
whichimage++
else {
randomOrder = radomSlideShow();
whichimage=0;
}
setTimeout("slideit()",slideshowspeed)
}
slideit()

//-->
</script>
--
ASM
Nov 11 '06 #2
Hello, thank you very much for your help! However...it doesn't work for
me. I've tried variations and every which way of the amended code but
it still doesn't slide randomly, stops sliding all together w/ links
broken or doesn't work at all (empty widget). If you can patiently bare
with me, can you kindly write the whole code again so that I can just
copy and paste it? I feel that I'm almost there but I'm missing
something. Oh, and in the random code, there's this: "function
radomSlideShow() {"
is it 'radom' or 'random'? Just wondering if that's part of the
problem. Anyhow, thanks again for your help.

Nov 11 '06 #3
ASM
mrtaka79 a écrit :
Hello, thank you very much for your help! However...it doesn't work for
me. I've tried variations and every which way of the amended code but
it still doesn't slide randomly, stops sliding all together w/ links
broken or doesn't work at all (empty widget). If you can patiently bare
with me, can you kindly write the whole code again so that I can just
copy and paste it? I feel that I'm almost there but I'm missing
something. Oh, and in the random code, there's this: "function
radomSlideShow() {"
is it 'radom' or 'random'? Just wondering if that's part of the
problem. Anyhow, thanks again for your help.
Did I make a mistake ?

the name of function has any importance, you just need to use it by its
name (could be $() or foo() or asm() ...)

Code tested :
=============

<a href="javascript:gotoshow()"><img border="0" width="300"
src="/OneMissedCall1.jpg" name="slide" height="150"/></a>

<script type="text/javascript">
<!--

/*
JavaScript Image slideshow:
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScript here!
*/

var slideimages=new Array()
var slidelinks=new Array()
var winslide = false;

// randomize
// function to create an array sorting indexes
// of array slideimages in random :

function randomSlideShow() {
var L = slideimages.length;
var R = new Array();
var k = 0;
while(k<L) {
var n = Math.floor(Math.random()*L)
var ok = true;
for(var i=0; i<R.length; i++)
if(R[i] == n) ok = false;
if(ok) { R[R.length] = n; k++ }
}
return R;
}

function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}

function slideshowlinks(){
for (i=0;i<slideshowlinks.arguments.length;i++)
slidelinks[i]=slideshowlinks.arguments[i]
}

function gotoshow(){
if (!window.winslide||winslide.closed)
winslide=window.open('','','width=600,height=500,r esizable=1')
winslide.location=slidelinks[whichlink]
winslide.focus()
}

//-->
</script>

<a href="javascript:gotoshow()"><img border="0" width="300"
src="OneMissedCall1.jpg" name="slide" height="150"/></a>

<script type="text/javascript">
<!--

//configure the paths of the images, plus corresponding target links
slideshowimages("/OneMissedCall1.jpg","/2LDK1.jpg","/TokyoZombie-001.jpg")
slideshowlinks("/one-missed-call.html","/2ldk.html","/tokyo-zombie.html")

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=4000

// new array of random indexes
var randomOrder = randomSlideShow();

var whichlink=0;
var whichimage=0;

function slideit(){
if (!document.images)
return
whichlink=randomOrder[whichimage];
document.images.slide.src=slideimages[whichlink].src
if (whichimage<slideimages.length-1)
whichimage++
else {
randomOrder = randomSlideShow();
whichimage=0;
}
setTimeout("slideit()",slideshowspeed)
}
slideit()

//-->
</script>
--
ASM
Nov 11 '06 #4
Lee
mrtaka79 said:
>
Okay, first of all, I'm a complete noob, so go easy on me. I have this
code that works perfectly for me. The only thing I want to add is to
randomize the pictures/links that show up. Can anyone just tell me
where to add additional code to the following? BTW this is the only
code I could find that works in my Beta Blogger sidebar.
I don't really like that code. I made some easy fixes,
mostly adding the "type" attribute to the script tag, but
left most of it alone, except to add code to randomize the
images.
<a href="javascript:gotoshow()"><img border="0" width="300"
src="/OneMissedCall1.jpg" name="slide" height="150"/></a>
<script type="text/javascript">

// Random and Deal from http://www.merlyn.demon.co.uk/js-randm.htm
// A much better source than javascriptkit.com, apparently.

function Random(N) {
return Math.floor(N * (Math.random() % 1));
}
function Deal(N) {
var J, K, Q = new Array(N);
for (J = 0; J < N; J++) {
K = Random(J + 1);
Q[J] = Q[K];
Q[K] = J;
}
return Q;
}
/*
JavaScript Image slideshow:
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScript here!
*/

var slideimages=new Array()
var slidelinks=new Array()
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}

function slideshowlinks(){
for (i=0;i<slideshowlinks.arguments.length;i++)
slidelinks[i]=slideshowlinks.arguments[i]
}

function gotoshow(){
if (!window.winslide||winslide.closed)
winslide=window.open(slidelinks[randomized[whichlink]])
else
winslide.location=slidelinks[randomized[whichlink]]
winslide.focus()
}

</script>

<a href="javascript:gotoshow()"><img border="0" width="300"
src="OneMissedCall1.jpg" name="slide" height="150"/></a>
<script type="text/javascript">

//configure the paths of the images, plus corresponding target links
slideshowimages("/OneMissedCall1.jpg","/2LDK1.jpg","/TokyoZombie-001.jpg")
slideshowlinks("/one-missed-call.html","/2ldk.html","/tokyo-zombie.html")

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=4000

// Create a randomized set of indices:
var randomized=Deal(slideimages.length);

var whichlink=0
var whichimage=0
function slideit(){
if (!document.images)
return
document.images.slide.src=slideimages[randomized[whichimage]].src
whichlink=whichimage
if (whichimage<slideimages.length-1)
whichimage++
else
whichimage=0
setTimeout("slideit()",slideshowspeed)
}
slideit()

</script>
--

Nov 11 '06 #5
It works perfectly! Thank you all for your patience. Couldn't have done
it without you, keep up the good work!

Nov 11 '06 #6
In message <11**********************@e3g2000cwe.googlegroups. com>, Fri,
10 Nov 2006 19:36:42, mrtaka79 <mr******@gmail.comwrites
...
The only thing I want to add is to randomize the pictures/links that
show up.
...
Firstly, ISTM, one must consider what "randomise" of pictures 1 to N
should mean, if in a show of infinite length.

I see two limiting cases :

A) The pictures are chosen at random, independently of what went before.
The chances of a repeat, in any one display, of the previous picture
are 1 in N; the chances of a repeat, in a total of N draws, must
exceed 50%.

B) The pictures are assigned, once and for all, a random order; and that
order is repeatedly cycled through. Picture P is either always or
never followed by picture Q.

Then there's

C) One can draw the pictures in random order, show them all, and repeat
draw-and-show. There's then a 1 in N chance of a repeat at the end
of each cycle, and ISTM a 2 in N chance of a picture being repeated
with a single one in between.

Now consider

D) Deal, once and for all, the set of N picture-numbers into an array X.
Then, for each display, select at random one of the first M entries;
show it; and move its entry to the end of the array, allowing other
entries to move forwards. Easily coded, of course.

If M==N, we have Case A.
If M==1, we have Case B.
If M==N-K, repeats of a picture occur at intervals containing at least K
other pictures.
But, as in Case A but not Case B, it is still possible (if Random is
perfectly random, which it is not), for an unlucky picture never to be
shown; there is no upper limit on the interval between showings of a
given picture.

QUERY : is there a simple elegant method including the advantage of Case
D but fixing the defect?

Of course, one could maintain for each entry in the first M a countdown
of how long it had been there, starting at M+J, and select an entry when
its count reached 0, treating it as if it had been chosen as before. But
I see no better way of doing that than a loop through all M decrementing
an array element ...

Test Code for Case D :

function Slides() { var N = 8, M = 4, Q = Deal(N), A = [], j, r, k, t
document.writeln("Q: ", Q)
for (j=0 ; j<64 ; j++) { r = Random(M) ; t = A[j] = Q[r]
for (k=r+1 ; k<N ; k++) Q[k-1] = Q[k] ; Q[N-1] = t }
document.writeln("A: ", A.join(""), "\nQ: ", Q) }

Can the k loop be *better* written with array methods ?

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1644
by: Patrick Fitzgerald | last post by:
I have a GNU licensed Javascript slideshow script: http://slideshow.barelyfitz.com/ Recently some users have complained about problems in Mac IE; unfortunately I don't have a Mac system that I...
2
3981
by: Susanna | last post by:
Hi all, I'm using the following slideshow script that I found on the web to display changing images with a crossfade effect. Eventually I will be adding many more images to the slideshow. The...
16
2856
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
1
1507
by: scorpion53061 | last post by:
I really like this javascript for an image slideshow. The only thing I woudl like to do differently is have a cell above the image and navigation that would allow text content to be placed. Does...
1
1343
by: David. E. Goble | last post by:
Hi all; I have the following files; index.html, sigsheader.js, sigsboby.js, smilesbody.js and smiles.js. The sourse is below. The page displays two manual slide shows... Each slideshow has a set...
7
1617
by: David. E. Goble | last post by:
Hi all; I have the following files; index.html, sigsheader.js, sigsboby.js, smilesbody.js and smiles.js. The sourse is below. The page displays two manual slide shows... Each slideshow has a set...
22
5098
by: bevoldjling | last post by:
Hi ! I need some help in putting together a website for our family gathering. Although I'm still pretty "green", I don't think what I need requires terribly advanced skills ...except for one...
8
1515
by: GabrielESandoval | last post by:
i currently use the code below to create a slideshow of images. i edited it so that its not as long. i currently have over 20 images i want to change it so that the images dont appear in the...
1
2281
pradeepjain
by: pradeepjain | last post by:
script> // (C) 2000 www.CodeLifter.com // http://www.codelifter.com // Free for all users, but leave in this header // NS4-6,IE4-6 // Fade effect only in IE; degrades gracefully //...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.