Okay…
I have an HTML file in a folder called “main site”. There are picture URLs in the following code. I need to know if I did it right, or if I need to use absolute urls… The folder “main site” contains a folder called “albums”.
The subfolders of “albums” are band names, each one containing a single .jpg image named “cover.jpg”. Tell me if I did this right. The script is supposed to create an array, and store the file paths in the array. Then, it’s supposed to use a “while” loop to preload the images, and then put them in an array. Now, here’s what I need… Tell me if I did the file paths right, and…
I need a function that I can assign to the “onmouseover” event handler of a [b]bunch
[code]
function swap(){
document.body.style.backgroundImage.src=”url(parameter)”;
}
I need to pass a parameter in the link:
<a href=”javascript://” onmouseover=”swap(fotos[x])”>Band Name</a>
where “fotos” is the array in my script that the pictures are put into, and you get the “x”.
Can you explain how to do that? I’d really like to use the array, instead of using onmouseover=”swap(freakin’ long file path)”
So, here’s my script so far. If I did [b]ANYTHING
I have a week or two to get this working. (the whole purpose of the script is to swap the background image depending on what link the user hovers over. Thus, the preloading…)
Here’s what I’ve got. If It’s wrong TELL ME SO, please. Thank you.
[code]
// JavaScript Document
//Script to preload images
//Create array
pics = new Array();
pics[0]=”/albums/3_doors_down/cover.jpg”;
pics[1]=”/albums/ac_dc/cover.jpg”;
pics[2]=”/albums/aiden/cover.jpg”;
pics[3]=”/albums/all_american_rejects/cover.jpg”;
pics[4]=”/albums/anthrax/cover.jpg”;
pics[5]=”/albums/black_eyed_peas/cover.jpg”;
pics[6]=”/albums/black_sabbath/cover.jpg”;
pics[7]=”/albums/blue_october/cover.jpg”;
pics[8]=”/albums/bob_dylan/cover.jpg”;
pics[9]=”/albums/brad_paisley/cover.jpg”;
pics[10]=”/albums/bush/cover.jpg”;
pics[12]=”/albums/coheed_and_cambria/cover.jpg”;
pics[13]=”/albums/creed/cover.jpg”;
pics[14]=”/albums/ccr/cover.jpg”;
pics[15]=”/albums/csn/cover.jpg”;
pics[16]=”/albums/evanescence/cover.jpg”;
pics[17]=”/albums/fmstatic/cover.jpg”;
pics[18]=”/albums/green_day/cover.jpg”;
pics[19]=”/albums/gnr/cover.jpg”;
pics[20]=”/albums/hawthorne_heights/cover.jpg”;
pics[21]=”/albums/hoobastank/cover.jpg”;
pics[22]=”/albums/priest/cover.jpg”;
pics[23]=”/albums/coil/cover.jpg”;
pics[24]=”/albums/zeppelin/cover.jpg”;
pics[25]=”/albums/lenny_kravitz/cover.jpg”;
pics[26]=”/albums/skynyrd/cover.jpg”;
pics[27]=”/albums/megadeth/cover.jpg”;
pics[28]=”/albums/metallica/cover.jpg”;
pics[29]=”/albums/motorhead/cover.jpg”;
pics[30]=”/albums/nirvana/cover.jpg”;
pics[31]=”/albums/quiet_riot/cover.jpg”;
pics[32]=”/albums/relient_k/cover.jpg”;
pics[33]=”/albums/slayer/cover.jpg”;
pics[34]=”/albums/beach_boys/cover.jpg”;
pics[35]=”/albums/beatles/cover.jpg”;
var i = 0;
var j = 0;
// ^ Declare increment variable
while(i < pics.length){
image1 = new Image();
fotos = new Array()
fotos[j] = pics[i];
// ^ Create a new image in cache
image1.src = pics[i];
// ^ Set new image source to the image path
// provided in pics[i], where “i” references
// the array element with the same value
// as the increment variable “i”
i++;
j++;
// Shorthand for “i = i + 1”, which mathematically
// adds the number 1 to “i”, so that on the next
// loop iteration, the image source is set to the
// value of the next array element
//
//
}
// ^ Script to preload images from
// values of elements contained in
// the “pics” array
// End image preloading script
If I did the file paths wrong, please let me know immediately.
I have no idea how to handle file paths in javascript… I’ve only ever
swapped images that are in the same directory… 😮