473,473 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Optimization

Hey everyone is there a way in which I could optimize my code with
just one for loop (see code below). I've come across this issue a few
times now and haven't found a solution as yet.. As you can see from
the code below I'm reusing the same loop throughout three functions, I
basically see this as a waste. Is there a more efficient way where I
could use the for loop just the once.

var overStates = [
['0','imgs/membersHome/set01Over.jpg', 'imgs/membersHome/
set01Up.jpg'],
['1','imgs/membersHome/set02Over.jpg', 'imgs/membersHome/
set02Up.jpg'],
['2','imgs/membersHome/set03Over.jpg', 'imgs/membersHome/
set03Up.jpg'],
];

function imgState(event){
var target = getTarget(event, 'a'), i;
for(i = 0; i < overStates.length; i++){
amyObj.removeImgStates(i, 2);
if(overStates[i][0] == target.firstChild.name){
target.firstChild.src = overStates[i][1];
}
}
}

function overState(event){
var target = getTarget(event, 'a'), i;
for(i = 0; i < overStates.length; i++) {
if(overStates[i][0] == target.firstChild.name) {
target.firstChild.src = overStates[i][1];
}
}
}

function outState(event){
var target = getTarget(event, 'a'), i;
for(i = 0; i < overStates.length; i++){
if(overStates[i][0] == target.firstChild.name)
{
target.firstChild.src = overStates[i][2];
}
}
}

Cheers!

DoomedLung

Aug 13 '07 #1
2 1210
DoomedLung wrote:
Hey everyone is there a way in which I could optimize my code with
just one for loop (see code below). I've come across this issue a few
times now and haven't found a solution as yet..
http://pointedears.de/scripts/test/dom/hoverMe/ might give you some ideas.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 13 '07 #2
On Aug 13, 1:52 am, DoomedLung <doomedl...@googlemail.comwrote:
Hey everyone is there a way in which I could optimize my code with
just one for loop (see code below). I've come across this issue a few
times now and haven't found a solution as yet.. As you can see from
the code below I'm reusing the same loop throughout three functions, I
basically see this as a waste. Is there a more efficient way where I
could use the for loop just the once.

function makeHandler(idx){
return function (event) {
var target = getTarget(event, 'a'), i;
for(i = 0; i < overStates.length; i++){
if(overStates[i][0] == target.firstChild.name)
{
target.firstChild.src = overStates[i]
[idx];
}
}
}
}
var overState = makeHandler(1);
var outState = makeHandler(2);

By the way, you should probably reconsider re-setting <img-tag>.src,
as IE6 has bugs when rendering images that are not the same
proportions. Create a fresh image tag instead (using
img.cloneNode(false).

If you're using images in a navigation bar for clickable links, try
using CSS background images using :hover replacement instead. You can
avoid JS altogether if that's the case.

-David

Aug 13 '07 #3

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

Similar topics

3
by: Alex Vinokur | last post by:
For instance, we need to measure performance of assignment 'ch1 = ch2' where ch1 and ch2 are of char type. We need to do that for different optimization levels of the same compiler. Here is...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: AC Slater | last post by:
Whats the simplest way to change a single stored procedures query optimization level? In UDB8 that is. /F
2
by: Eugene | last post by:
I am trying to set query optimization class in a simple SQL UDF like this: CREATE FUNCTION udftest ( in_item_id INT ) SPECIFIC udftest MODIFIES SQL DATA RETURNS TABLE( location_id INT,...
12
by: WantedToBeDBA | last post by:
Hi all, db2 => create table emp(empno int not null primary key, \ db2 (cont.) => sex char(1) not null constraint s_check check \ db2 (cont.) => (sex in ('m','f')) \ db2 (cont.) => not enforced...
24
by: Kunal | last post by:
Hello, I need help in removing if ..else conditions inside for loops. I have used the following method but I am not sure whether it has actually helped. Below is an example to illustrate what I...
21
by: mjbackues at yahoo | last post by:
Hello. I'm having a problem with the Visual Studio .net (2003) C++ speed optimization, and hope someone can suggest a workaround. My project includes many C++ files, most of which work fine...
5
by: wkaras | last post by:
I've compiled this code: const int x0 = 10; const int x1 = 20; const int x2 = 30; int x = { x2, x0, x1 }; struct Y {
2
by: db2admin | last post by:
hi, I have query which runs great when optimization level is changed to 3 but does not run fine with default optimization level of 5. since this is a query in java code, i do not know how can i...
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
1
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
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,...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.