Jump to content

Triple Loop

Recommended Posts

I have this JS file that takes care of my rollovers. I need to add 2 styles (3 total). I want to create loops to declare my rollovers.Currently what I have:home_e = new Image(118,37); home_e.src = '/images/home_e.jpg';about_e = new Image(118,37); about_e.src = '/images/about_e.jpg';portfolio_e = new Image(118,37); portfolio_e.src = '/images/portfolio_e.jpg';contact_e = new Image(116,37); contact_e.src = '/images/contact_e.jpg';home_e_hover = new Image(118,37); home_e_hover.src = '/images/home_arrow_e.jpg';about_e_hover = new Image(118,37); about_e_hover.src = '/images/about_arrow_e.jpg';portfolio_e_hover = new Image(118,37); portfolio_e_hover.src = '/images/portfolio_arrow_e.jpg';contact_e_hover = new Image(116,37); contact_e_hover.src = '/images/contact_arrow_e.jpg';This is only 1 style (will become blue style) and 1 language. I have French and English for each button and styles blue, red, and green.This is an example of what I want:home_red_e = new Image(118,37); home_red_e.src = '/images/red/home_e.jpg';home_red_e_hover = new Image(118,37); home_red_e_hover.src = '/images/red/home_arrow_e.jpg';So is there a way to create some kind of loop to replace all this text?I have 8 buttons total for 1 language (1 base and 1 hover). I have 2 languages (english and french) and I have 3 styles (blue, red, green).I got this so far:

//Buttons array	var buttons = new Array(4);	buttons[0] = "home";	buttons[1] = "about";	buttons[2] = "portfolio";	buttons[3] = "contact";		//Languages array	var languages = new Array(2);	languages[0] = "e";	langauges[1] = "f";		//Styles array	var styles = new Array(3);	styles[0] = "blue";	styles[1] = "red";	styles[2] = "green";		var i,j,k;		while(i < 4) {		while(j < 3) {			while(k < 2) {				buttons[i]_styles[j]_languages[k] = new Image(118,37);				buttons[i]_styles[j]_languages[k].src = "/images/" + buttons[i] + "_" + languages[k] + ".jpg";				buttons[i]_styles[j]_languages[k]_hover = new Image(118,37);				buttons[i]_styles[j]_languages[k]_hover.src = "/images/" + buttons[i] + "_arrow_" + languages[k] + ".jpg";				i++;				j++;				k++:			}		}	}

Link to post
Share on other sites

Actually I thought about something during lunch.All that happens when I hover over a navigation image is I load a duplicate of the original image and add an arrow. I could simply add the arrow with css on hover and no need of JS.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...