473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Add randomizing function to fade-effect slideshow?

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 thing is, I ALSO have
to make it so the images will load randomly. I have looked at a
number of scripts for random-loading slideshows, but I have to find a
way to COMBINE this fading-image script (or, a different fading-image
script, if necessary) with a randomizing function. I haven't been
able to find a script online that does both. Unfortunately I don't
know how to code Javascript by hand and I haven't had any success
trying to hack this script myself to add the randomizing element. I
imagine that there is probably a fairly simple way to do it by adding
a line or two of code, but I don't know how to make it work...if
anyone can enlighten me, I'd be oh, so grateful.

Also, by the way: this crossfade slideshow only shows the fade effect
on PC's. Does anyone know of a script that makes this effect work on
the Mac too? (Also, on a Mac, this script does allow the images to
change, with no fade effect, BUT it is quite buggy and sometimes the
images start flashing around strangely...another problem. Any
ideas...?)

Thanks--
Susanna

Code:
In the header:

<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

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 7000

// Duration of crossfade (seconds)
var crossFadeDuration = 4

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'slideshow/1.jpg'
Pic[1] = 'slideshow/2.jpg'
Pic[2] = 'slideshow/3.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]
}

function runSlideShow(){
if (document.all){
document.images.SlideShow.style.filter="blendTrans (duration=2)"
document.images.SlideShow.style.filter="blendTrans (duration=crossFadeDuration)"
document.images.SlideShow.filters.blendTrans.Apply ()
}
document.images.SlideShow.src = preLoad[j].src
if (document.all){
document.images.SlideShow.filters.blendTrans.Play( )
}
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)
}
</script>

In the body:

<td id="VU" height=72 width=160><img src="slideshow/1.jpg"
name='SlideShow' width="160" height="72"></td>
Jul 20 '05 #1
2 3969
"Susanna" <we*********@ciis.edu> wrote in message
news:4b**************************@posting.google.c om...
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 thing is, I ALSO have
to make it so the images will load randomly. I have looked at a
number of scripts for random-loading slideshows, but I have to find a
way to COMBINE this fading-image script (or, a different fading-image
script, if necessary) with a randomizing function. I haven't been
able to find a script online that does both. Unfortunately I don't
know how to code Javascript by hand and I haven't had any success
trying to hack this script myself to add the randomizing element. I
imagine that there is probably a fairly simple way to do it by adding
a line or two of code, but I don't know how to make it work...if
anyone can enlighten me, I'd be oh, so grateful.

Also, by the way: this crossfade slideshow only shows the fade effect
on PC's. Does anyone know of a script that makes this effect work on
the Mac too? (Also, on a Mac, this script does allow the images to
change, with no fade effect, BUT it is quite buggy and sometimes the
images start flashing around strangely...another problem. Any
ideas...?)

Thanks--
Susanna

Code:
In the header:

<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

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 7000

// Duration of crossfade (seconds)
var crossFadeDuration = 4

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'slideshow/1.jpg'
Pic[1] = 'slideshow/2.jpg'
Pic[2] = 'slideshow/3.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]
}

function runSlideShow(){
if (document.all){
document.images.SlideShow.style.filter="blendTrans (duration=2)"
document.images.SlideShow.style.filter="blendTrans (duration=crossFadeDuratio
n)" document.images.SlideShow.filters.blendTrans.Apply ()
}
document.images.SlideShow.src = preLoad[j].src
if (document.all){
document.images.SlideShow.filters.blendTrans.Play( )
}
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)
}
</script>

In the body:

<td id="VU" height=72 width=160><img src="slideshow/1.jpg"
name='SlideShow' width="160" height="72"></td>

Okay, here's an *ugly* solution -- I'm sure others will let me know just how
ugly.
Add the following above the comment "// do not edit anything below this
line":

// Populate rand() array
var pics = new Array(Pic.length);
var rand = new Array(Pic.length);
do {
for (var i=0; i<Pic.length; i++) {
var seed = parseInt(Math.random()*1000)%Pic.length;
if (rand[i] == null) {
if (pics[seed] == null) {
rand[i] = seed;
pics[seed] = i;
}
}
}
}
while (rand.join("").length < Pic.length);
And change one line below the comment "// do not edit anything below this
line":
preLoad[i].src = Pic[i]
becomes:
preLoad[i].src = Pic[rand[i]]
Note that with your code the first image displayed will always be
"slideshow/1.jpg".

Watch for word-wrap.
Jul 20 '05 #2
JRS: In article <c4rEb.597098$Fm2.545352@attbi_s04>, seen in
news:comp.lang.javascript, McKirahan <Ne**@McKirahan.com> posted at Thu,
18 Dec 2003 23:51:36 :-

var seed = parseInt(Math.random()*1000)%Pic.length;


No point in converting to a string and back; and you may have the wrong
result range; read the newsgroup FAQ, 4.22.

BTW, that is a case when parseInt does not need a second parameter. If
parseInt does not need a second parameter, then it is *probably* not
necessary to use parseInt.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3

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

Similar topics

1
by: Jonathan | last post by:
Hi Would anyone be able to tell me of an easy way to get fast fade in fade out in VB6? I need a method that can fade a whole screen very smoothly and it would be nice if it is compatible with...
1
by: jase_dukerider | last post by:
Hi I have an assignment to hand in shortly for which I am after some guidance. The task is to read a WAV file, request a fade in /out time for the track from the user and the do the fade by...
1
by: Acer | last post by:
Does somebody know a javascript function to show an image and fade-out to another picture ? thanks for any help
1
by: Sakharam Phapale | last post by:
Hi All, I am developing an application like sound recorder. While recording if there is a silence for more than given time (say 5 seconds), Recording should be paused.
1
by: Brent | last post by:
I wrote a "show div"* function that fires (and sets a DIV's "display" style to '') when the user mouses over a certain area on the screen. I also have a "fade div"** function that fires when the...
0
by: aziz001 | last post by:
My forms have the standard 'Control' BackColor. When I use the normal fade in algorithm the fade in colour is black and then the form suddenly pops up. How do I fade in using the Control color (or...
1
by: Luciano A. Ferrer | last post by:
Hello! Im trying to do a few fade effects here http://relojurbano.com.ar/scalda/baseporque.php using fadomatic ( http://chimpen.com/fadomatic/ ) I dont know if fadomatic is a good solution...
2
by: hon123456 | last post by:
Dear all, I got four jpg file, I want to made them fade in / fade out continuously and repeatly in the same table cell of html (e.g. in the same <td></td>) How can I do that in javascript. Please...
5
by: fade | last post by:
Good afternoon, I need some advice on the following: I've got a class that has a member std::vector<CStringm_vFileName and a member CString m_path; The vector contains a bunch of filenames with...
5
by: Gretsch | last post by:
Hi, Can someone help me with the command format please. I have a function (called fade) that was 3 parameters: the first 2 are colours therefore formatted #123456 and the 3rd is a number of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.