Image opacity flicker and getElementById

M

mhoeneveld

I am writing a small script to fade the opacity of an image/object.
The script itself works fine only I do have some unwanted behaviour.

I do use a tablecell object and the mouseover/mouseout to activate the
script.
In the same cell are some links listed and when you move the cursor
over the links the image starts to flicker. This is because of the
getElementById that identifies each link as an object.

Anyone knows how I can solve this behaviour?
(Below is the sourcecode I use)

Thanks a lot for your help in advance.
Maurice Hoeneveld
(e-mail address removed)

<HTML>
<HEAD>
<TITLE></TITLE>

<SCRIPT language="JavaScript1.2">
<!--

function opacity(id, opacStart, opacEnd, milisec) {
// speed for each frame
var speed = Math.round(milisec / 100 );
var timer = 0;

// determine the direction for the blending, if start and end are the
same nothing happens
if(opacStart > opacEnd) {
for(i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
} else if(opacStart < opacEnd) {
for(i = opacStart; i <= opacEnd; i++) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
}
}

// change the opacity for different browsers
function changeOpac(opacity, id) {
var object = document.getElementById(id).style;
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
}


//-->
</SCRIPT>

</HEAD>
<BODY BGCOLOR=#AAAAAA>


<CENTER>
<TABLE BORDER=0 WITH=800>
<TR>
<TD WIDTH=200 VALIGN=top id="image1"
STYLE="filter:alpha(opacity=50);-moz-opacity:0.5"
onMouseover="opacity('image1',50,100,2000)"
onMouseout="opacity('image1',100,50,2000)"
<IMG SRC="image1.jpg" width=200 height=150 BORDER=0><BR>
<A HREF="link1.html" TARGET=_BLANK>link1<BR>
<A HREF="link2.html" TARGET=_BLANK>link2<BR>
<A HREF="link3.html" TARGET=_BLANK>link3<BR>
<A HREF="link4.html" TARGET=_BLANK>link4<BR>
<A HREF="link5.html" TARGET=_BLANK>link5<BR>
<A HREF="link6.html" TARGET=_BLANK>link6<BR>
</CENTER>
</TD>
</TR>
</TABLE>


</CENTER>

</BODY>
</HTML>
 
S

Stephen Chalmers

mhoeneveld said:
I am writing a small script to fade the opacity of an image/object.
The script itself works fine only I do have some unwanted behaviour.

I do use a tablecell object and the mouseover/mouseout to activate the
script.
In the same cell are some links listed and when you move the cursor
over the links the image starts to flicker. This is because of the
getElementById that identifies each link as an object.

Actually, I think the cause is that hovering the links is triggering
mouseout events for the table cell. You could re-code the function so
that once a transition has started, it cannot be halted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top