Fan924 wrote:
How do I add random number generation to this background image slide
show? Everything I try kills if. TIA
_______________ _______________ _______
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="GENERATOR " content="Micros oft FrontPage 4.0">
<meta name="ProgId" content="FrontP age.Editor.Docu ment">
<title>New Page 2</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaS cript1.2">
The language attribute was deprecated many years ago, type is reqired, use:
<script type="text/javascript">
Indented code is easier to read for most of us.
var pic=new Array()
pic[0]="pic/./000.bmp"
pic[1]="pic/./001.jpg"
pic[2]="pic/./002.jpg"
pic[3]="pic/./003.jpg"
pic[4]="pic/./004.jpg"
pic[5]="pic/./005.jpg"
pic[6]="pic/./006.jpg"
pic[7]="pic/./007.jpg"
pic[8]="pic/./008.jpg"
pic[9]="pic/./009.jpg"
That can be written more concisely as an Array literal:
var pic = ["pic/./000.bmp", "pic/./001.jpg",
"pic/./002.jpg", "pic/./003.jpg",
...
];
var img=new Array()
var img = [];
for (i=0;i<pic.leng th;i++){
Don't forget to declare variables. It doesn't really matter here but is
a good habbit:
for (var i=0; i<pic.length; i++){
img[i]=new Image()
img[i].src=pic[i]
}
var enf=-1
I understand why you've used -1 here, but consider using 0 and setting
your background image to pic/./000.bmp otherwise your visitors will have
to wait for the entire page and all images to load, then another second
before any background image is shown. So use:
<body style="backgrou nd-image: url('pic/./000.bmp');">
function Slide(){
By convention, function names that start with capital letters are
reserved for constructors.
if (enf<pic.length-1)
enf++
else
enf=0
That can be written as:
var enf = 0;
function Slide() {
enf = ++enf % pic.length;
document.body.b ackground=img[enf].src
document.body.s tyle.background Image = 'url("'+img[enf].src+'")';
}
if (document.all|| document.getEle mentById)
The intention of feature detection is that you test for the feature that
you want to use. It is a bad strategy to test for some other feature to
infer support for the one you actually want to use.
window.onload=n ew Function('setIn terval("Slide() ",1000)')
The Function constructor is unnecessary here and equivalent to the use
of eval, use:
window.onload = function(){
window.setInter val(slide, 1000);
}
--
Rob