472,807 Members | 3,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,807 software developers and data experts.

Delay and condition on expanding drop-down menu

Hi NG,

I hope someone in here is able to help me in this matter. The problem:

I have created a Javascript drop-down menu which expands when moving the
mouse into a tablecell (calls my Expand() function at onMouseover on the
<td>-element).

My question is now this: How do I delay the expansion of the
menu for e.g. 500 ms in order to keep it from happening "by accident". A
simple delay is no good, since the mouse may be gone when the time has
elapsed (i.e. passed by "by accident").

I need a way of checking whether the mouse is still on the tablecell after
an amount of time has gone by (the script should wait for a while, then
check, and if yes, then expand).

How do I do this when all I have to go by is a mouseOver event?

Thanks!

regards,

M.L.
Jul 23 '05 #1
1 2363
"M.L." wrote:
Hi NG,

I hope someone in here is able to help me in this matter. The problem:

I have created a Javascript drop-down menu which expands when moving the
mouse into a tablecell (calls my Expand() function at onMouseover on the
<td>-element).

My question is now this: How do I delay the expansion of the
menu for e.g. 500 ms in order to keep it from happening "by accident". A
simple delay is no good, since the mouse may be gone when the time has
elapsed (i.e. passed by "by accident").

I need a way of checking whether the mouse is still on the tablecell after
an amount of time has gone by (the script should wait for a while, then
check, and if yes, then expand).

How do I do this when all I have to go by is a mouseOver event?

Thanks!

regards,

M.L.


In the onmouseover event, you use setTimeout() to trigger a function that
actually does the popup. In onmouseout, you check to see if the timer is still
active, if it is, you cancel the timer:

<a href="#"
onmouseover="delayAction();return true;"
onmouseout="clearAction();return true;">Test</a>
<script type="text/javascript">
function delayAction(e) {

// this function retrieves any information
// you need about the event, sets those values
// to global variables and sets up the actual
// action to happen in a specified period of time

// remember the event that triggered this
// function in case you need it later
e = e || event;

if (e) {
// retrieve any information you need about
// the event and set that information to
// global variables
window.ActionX = (e.pageX ? e.pageX : e.clientX);
window.ActionY = (e.pageY ? e.pageY : e.clientY);
// set the actual action to happen in ~500ms
window.ActionTimer = setTimeout(doAction, 500);
}
}
function clearAction() {

// this function clears the action if
// it hasn't actually happened yet

if (window.ActionTimer) {
// if they moused out and there is
// a running timer, clear it
clearTimeout(window.ActionTimer);
window.ActionTimer = null;
}
}

function doAction() {

// this function does the actual work
// it picks up any information from the
// global variables set in 'delayAction'

alert('Mouse at: ' + window.ActionX + ',' + window.ActionY);

// this guarantees you can call setTimeout
// with a reference to 'doAction', rather
doAction.toString = function() {
return 'doAction();';
}
}
</script>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2

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

Similar topics

2
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
14
by: Des L. Davis | last post by:
System: Dell PowerEdge Server with 3 GB RAM, 2.4 GHz Celeron Software: Microsoft SQL Server 2000 Enterprise running on Windows 2003 Server Software: Microsoft SQL Server 2000 Enterprise running on...
2
by: lynology | last post by:
My program takes in a key pressed value from the main routine and based on the key pressed, it selects the command to be executed. The problem I have is in creating a delay timer so that a message...
2
by: amos_s12 | last post by:
Hello everybody Is there a possibility to make a delay between two sql statements, namely one sql statement is performed, then there is a delay of some seconds and then rhe next statement is...
10
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
7
by: mfeingold | last post by:
I am working on a system, which among other things includes a server and a ..net control sitting in an html page and connected to the server. I ran into a couple of problems, you guys might have...
1
by: CKane | last post by:
i am trying to build a "missed message" queue on a C# TCP server. many of the devices connecting are mobile and may drop out in bad signal areas. i want to store any messages missed for when they...
24
by: Chen Shusheng | last post by:
Hello, I want to write a time delay function like "Timedelay(float time_lenth){}". When execute it, it will delay some seconds as long as "time_lenth" indicating. Could you help on how to write...
1
by: leshka82 | last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.