i am trying to show and hide a div when onmouseover and onmouseover another div element.
i am setting a setTimeout duration on onmouseout to delay the hiding of div for around two second
The problem is that when i mouseover an element and then onmouseout it and then back again mouseovers that element before the timeout, the element still gets hidden
so i put a flag=1 when i mouseover the element and flag=0 at mouseout and checked the value of the flag when calling the hiding function
still there was a problem
if i repeated mouseover and mouseout the element, at the time when the hiding function is called, if value of flag was 0, it hides the element before the timeout of last onmouseout even called
dont know if i made it any clear
here is my code
[HTML]<div id="checking" style="width:80 px; height:20px; background-color:#666666; color:#FFFF00"> hover here</div>[/HTML]
[HTML]<div id="mydiv" style="position :absolute; top:40px; left:300px; width:500px; height:400px; background-color:#33CCFF; z-index:1000; display:none " ></div>[/HTML]
[CODE=javascript]
var flag=0;
var d=document.getE lementById('myd iv');
var s=document.getE lementById('che cking');
function hiding()
{
if(flag!=0)
return
d.style.display ='none';
}
s.onmouseover=f unction(){
d.style.display ='';
flag=1;
}
s.onmouseout=fu nction(){
flag=0;
setTimeout('hid ing()',2000);
}
[/CODE]
i am setting a setTimeout duration on onmouseout to delay the hiding of div for around two second
The problem is that when i mouseover an element and then onmouseout it and then back again mouseovers that element before the timeout, the element still gets hidden
so i put a flag=1 when i mouseover the element and flag=0 at mouseout and checked the value of the flag when calling the hiding function
still there was a problem
if i repeated mouseover and mouseout the element, at the time when the hiding function is called, if value of flag was 0, it hides the element before the timeout of last onmouseout even called
dont know if i made it any clear
here is my code
[HTML]<div id="checking" style="width:80 px; height:20px; background-color:#666666; color:#FFFF00"> hover here</div>[/HTML]
[HTML]<div id="mydiv" style="position :absolute; top:40px; left:300px; width:500px; height:400px; background-color:#33CCFF; z-index:1000; display:none " ></div>[/HTML]
[CODE=javascript]
var flag=0;
var d=document.getE lementById('myd iv');
var s=document.getE lementById('che cking');
function hiding()
{
if(flag!=0)
return
d.style.display ='none';
}
s.onmouseover=f unction(){
d.style.display ='';
flag=1;
}
s.onmouseout=fu nction(){
flag=0;
setTimeout('hid ing()',2000);
}
[/CODE]
Comment