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] -
var flag=0;
-
var d=document.getElementById('mydiv');
-
var s=document.getElementById('checking');
-
function hiding()
-
{
-
if(flag!=0)
-
return
-
d.style.display='none';
-
}
-
s.onmouseover=function(){
-
d.style.display='';
-
flag=1;
-
}
-
s.onmouseout=function(){
-
flag=0;
-
setTimeout('hiding()',2000);
-
}
-
17 2021
i think i got it working but not too sure
I dont know if it can be achieved by any other way as well
i changed my code to include a timestamp in flag
and checked for the difference in current time and timestamp -
var flag=(new Date()).getTime();
-
var d=document.getElementById('mydiv');
-
var s=document.getElementById('checking');
-
function hiding()
-
{
-
if((new Date()).getTime()-flag<1999)
-
return
-
d.style.display='none';
-
}
-
s.onmouseover=function(){
-
-
d.style.display='';
-
-
flag=(new Date()).getTime();
-
}
-
s.onmouseout=function(){
-
flag=(new Date()).getTime();
-
setTimeout('hiding()',2000);
-
}
-
acoder 16,027
Recognized Expert Moderator MVP
i think i got it working but not too sure
I dont know if it can be achieved by any other way as well
i changed my code to include a timestamp in flag
and checked for the difference in current time and timestamp
I think that should work. More robust than a simple flag.
yes i want to wait for a few seconds before hiding the div element if user has moved his mouse away from the hover element kinda putting a delayed hide but if the user gets back on the hover element before timeout of hiding of div, the div should not get hidden and a new timeout be set when the user hovers out of the hover element again
hehe where did your last post go
acoder 16,027
Recognized Expert Moderator MVP
hehe where did your last post go
Since you posted before I posted, it answered my question, so I deleted it. Didn't think you'd notice :p Still, it's good to confirm.
yea my last post was reply to your question and after posting i saw ur post not there :P
there is a little problem as well
when i put - if((new Date()).getTime()-flag<2000)
insted of - if((new Date()).getTime()-flag<1999)
the div sometimes stays there even when at timeout, not a big problem but just a difference of a millisecond removes it
but since i am checking for value less than 2000 ms, it should work every time as i am calling setTimeout function after 2000 ms
acoder 16,027
Recognized Expert Moderator MVP
there is a little problem as well
when i put - if((new Date()).getTime()-flag<2000)
insted of - if((new Date()).getTime()-flag<1999)
the div sometimes stays there even when at timeout, not a big problem but just a difference of a millisecond removes it
but since i am checking for value less than 2000 ms, it should work every time as i am calling setTimeout function after 2000 ms
I'm not sure of the timing issues. You should also test on a slower machine and see if that affects anything.
there is another problem now
i have put the functions i called at onmouseover and onmouseout on both the div elements now
and when i hover on 1st div, it opens the 2nd div
now if i put my 2nd div somewhat above the 1st div and take my mouse from 1st div to 2nd div without getting out from 1st div, the onmouseover event of 2nd div gets fired, and when i continue moving the mouse inside 2nd div and get out of 1st div, the onmouseout event of 1st div gets fired and that hides my 2nd div after 2 seconds even when i am hovering my mouse on 2nd div
here is my code
[HTML]<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div id="checking" style="width:80 px; height:20px; background-color:#666666; color:#FFFF00" onmouseover="sh ow()" onmouseout="del ayhide()">hover here</div>
<div id="mydiv" style="position :absolute; top:20px; left:60px; width:500px; height:400px; background-color:#33CCFF; z-index:1000; display:none " onmouseover="sh ow()" onmouseout="del ayhide()" ></div>
<script type="text/javascript">
var flag=(new Date()).getTime ();
var d=document.getE lementById('myd iv');
function hiding()
{
if((new Date()).getTime ()-flag<1998)
return
d.style.display ='none';
}
function show(){
d.style.display ='';
flag=(new Date()).getTime ();
}
function delayhide(){
flag=(new Date()).getTime ();
setTimeout('hid ing()',2000);
}
</script>
</body>
</html>[/HTML]
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dré |
last post by:
Hi,
I'm making a FAQ-page. To keep it a little synoptic, only the questions are
visible. When you klick on a certain question, the answer appears. You can
find an example at: http://www.aendekerk.be/zoom/uitklappen.htm
Suppose i click on "titel1", "tekst1" appears. When i click on "titel2",
"tekst2" appears. But also tekst1 remains visible. I don't want this. How
can i program this?
|
by: mcheu |
last post by:
Hi,
I'm trying to figure out how to hide text in a DIV block and then hide
and unhide it using javascript. In the code that follows, the message
is initially invisible, and when you click on the "show" link, it's
made visible and pops up bettween the two hyphen lines. When you
click on the "hide" link, it's made invisible again. Or at least
that's what is supposed to happen.
It does all of this just fine in IE5, IE5.5, and IE6. ...
|
by: Christopher Benson-Manica |
last post by:
Obviously, compiliant browsers that encounter
<script type="text/javascript">
<!--
// your script here
// -->
</script>
will either execute the script or ignore it completely. However, we are
encountering some browsers running on mobile phones that can't handle
|
by: ashkaan57 |
last post by:
Hi,
how can I hide / show a section of a page when a link is clicked?
Click on "show section" would show the section and change the link to
"hide section", clicking on "hide section" would hide it.
TIA.
|
by: c.anandkumar |
last post by:
Hi All -
I have some problems getting a small piece of javascript working
correctly for Firefox. Here is what I am trying to do -
1. I have a form (like a search form)
2. I have many groups of searchable fields in the fields
3. Each group can be expanded/collapsed by clicking on a link
"(Fewer|More) Options" which sits right next to the group title.
| |
by: EventListener |
last post by:
I have a folder/file tree that is dynamically generated from an xml
file. The way I've written it seems to work. Since I'm a fairly novice
javascript programmer, I'm concerned that there may be a hidden
downside to coding this way vs. hiding/showing using style.visibility.
My tree starts with only the top level folders showing. When the xml
for the tree loads, I have a recursive function that creates subtrees
for each folder, then saves...
|
by: Amber |
last post by:
The DataGrid allows you to make columns visible or invisible on demand
- even edit and other special columns. This article will show you how
it is done.
Some developers have reported problems controlling the visibility of
columns in the DataGrid control. The problem usually comes down to one
fact. The DataGrid has a property called AutoGenerateColumns. The
default value is "True". This means that when AutoGenerateColumns is
set to True,...
|
by: Charlie Dison |
last post by:
Hi There,
Should I be able to show and hide panels in an asp.net page without
requiring a postback? I thought there was a way to do this using java
script. Can anyone give me an example? I can't seem to find one that makes
sense. Thanks.
|
by: =?Utf-8?B?Sm9zaCBTY2htaWR0?= |
last post by:
I have a gridview that is being used for managing inventory. The default
view shows the stock currently available. When editing I don't want the
stock to be directly edited, rather the user will enter the amount of items
being added/removed.
When the user clicks the 'Edit' link I want to hide the stock column and
display a field for the TransactionAmt. I'm using the RowUpdating event to
execute some functions used by that field. I've...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |