473,626 Members | 3,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Absolute cursor location

How can I find the absolute cursor location? Where the mouse cursor is
located with repect to the body.
This way I can position an div tag where the mouse is, even if scrolled down
farther on the page.

Any help would be appreciated.
Sid Sidney

Nov 19 '05 #1
4 1672
Yes, but not with ASP.NET since that's executing at the server. What you
want to do is needed to do at the client which means JavaScript is the best
way to go.

For eaxmple dynamic and nice animated Menus are made with JavaScript and
DHTML.

best regards/
Lars

"Sid S." <Si**@discussio ns.microsoft.co m> skrev i meddelandet
news:93******** *************** ***********@mic rosoft.com...
How can I find the absolute cursor location? Where the mouse cursor is
located with repect to the body.
This way I can position an div tag where the mouse is, even if scrolled
down
farther on the page.

Any help would be appreciated.
Sid Sidney

Nov 19 '05 #2
How is this done with JavaScript?

"Lars Netzel" wrote:
Yes, but not with ASP.NET since that's executing at the server. What you
want to do is needed to do at the client which means JavaScript is the best
way to go.

For eaxmple dynamic and nice animated Menus are made with JavaScript and
DHTML.

best regards/
Lars

"Sid S." <Si**@discussio ns.microsoft.co m> skrev i meddelandet
news:93******** *************** ***********@mic rosoft.com...
How can I find the absolute cursor location? Where the mouse cursor is
located with repect to the body.
This way I can position an div tag where the mouse is, even if scrolled
down
farther on the page.

Any help would be appreciated.
Sid Sidney


Nov 19 '05 #3
I asume you know some Javascript already, Otherwise you'll need to learn
some basics in Javascript first. I haven't done anythign with Mouse
positions but i know it's not too hard, seen colegues do it.

One easy thing to check MousePosition things with is if you check the source
code for a site where they have those little images following the cursor
when you move. They were quite popular for a while in the beginning when
people started to make homepages and every now and then you bump into them.

If you do know the basics... then search for how to Build DHTML menus or
Javascript Menus... or just go to a site which have some cool client
features and check to see how they did it, that's how I learn things.. and
asking here of course.

best regards
/Lars

"Sid S." <Si**@discussio ns.microsoft.co m> skrev i meddelandet
news:CC******** *************** ***********@mic rosoft.com...
How is this done with JavaScript?

"Lars Netzel" wrote:
Yes, but not with ASP.NET since that's executing at the server. What you
want to do is needed to do at the client which means JavaScript is the
best
way to go.

For eaxmple dynamic and nice animated Menus are made with JavaScript and
DHTML.

best regards/
Lars

"Sid S." <Si**@discussio ns.microsoft.co m> skrev i meddelandet
news:93******** *************** ***********@mic rosoft.com...
> How can I find the absolute cursor location? Where the mouse cursor is
> located with repect to the body.
> This way I can position an div tag where the mouse is, even if scrolled
> down
> farther on the page.
>
>
>
> Any help would be appreciated.
> Sid Sidney
>


Nov 19 '05 #4
Hi Sid,

Here's an example Javascript that I'm using that moves a hidden DIV to the
location of the cursor and makes the DIV visible while the mouse is hovering
over a SPAN element:

====== Hidden DIV ======
<div id=divWinMsg style="BORDER-RIGHT:black 2px solid;
BORDER-TOP:black 2px solid; LEFT:300px; VISIBILITY:hidd en;
FONT:10pt comic sans ms; BORDER-LEFT:black 2px solid;
WIDTH:200px; PADDING-TOP:7px; BORDER-BOTTOM:black 2px solid;
POSITION:absolu te; TOP:800px; HEIGHT:120px;
TEXT-ALIGN:center; z-index:1; background-image:
url('images/winmsg_back.gif '); " />
====== Call to Javascript =======
<span id="win1" onmouseover="ri chToolTip('Test Message',event) ;"
onmouseout="hid eToolTip();" ><img src=images/awesome.gif height=35 width=35
/></span>
====== Javascript =======
<SCRIPT language=JavaSc ript>
function richToolTip(Win Msg, e)
{
var xCoord = 0;
var yCoord = 0;
var oScreenWidth = 0;
var oScreenHeight = 0;
var myElement;

if (document.layer s)
{
// old Netscape versions
myElement = document.divWin Msg;
if ((myElement == null) || (myElement == "undefined" ))
{ myElement = document.getEle mentById('divWi nMsg'); }

oScreenWidth = window.innerWid th;
oScreenHeight = window.innerHei ght;

xCoord = e.pageX + 15;
yCoord = e.pageY + 15;

if (xCoord + 200 + 5 > oScreenWidth)
{ xCoord = xCoord - 225; }
if (yCoord + 120 + 15 > oScreenHeight)
{ yCoord = yCoord - 150; }
}
else
{
// IE and newer versions of Netscape
myElement = document.getEle mentById('divWi nMsg');

if (myElement != null && myElement != "undefined" )
{
oScreenWidth = document.body.c lientWidth;
oScreenHeight = document.body.c lientHeight;

xCoord = e.clientX + document.body.s crollLeft +
document.docume ntElement.scrol lLeft + 15;
yCoord = e.clientY + document.body.s crollTop +
document.docume ntElement.scrol lTop + 15;

if (e.clientX + 200 + 5 > oScreenWidth)
{ xCoord = xCoord - 225; }
if (e.clientY + 120 + 15 > oScreenHeight)
{ yCoord = yCoord - 150; }
}
}
if (xCoord != 0 && yCoord != 0 && myElement != null && myElement !=
"undefined" )
{
myElement.inner HTML = WinMsg;
if (document.layer s)
{

if (typeof myElement.style .top != 'number')
{ eval("myElement .moveTo(xCoord, yCoord)"); }
else
{ myElement.style .top = yCoord;
myElement.style .left = xCoord; }

if ((myElement.sty le.visibility == null) ||
(myElement.styl e.visibility == "undefined" ))
{ myElement.visib ility = 'visible'; }
else
{ myElement.style .visibility = 'visible'; }

}
else
{
myElement.style .top = yCoord;
myElement.style .left = xCoord;
myElement.style .visibility = 'visible';
}
}
}

function hideToolTip()
{
if (document.layer s)
{
// old Netscape versions
var myElement = document.divWin Msg;
if ((myElement == null) || (myElement == "undefined" ))
{ myElement = document.getEle mentById('divWi nMsg'); }
if ((myElement.sty le.visibility == null) ||
(myElement.styl e.visibility == "undefined" ))
{ myElement.visib ility = 'hidden'; }
else
// IE and newer versions of Netscape
{ myElement.style .visibility = 'hidden'; }
}
else
{ document.getEle mentById('divWi nMsg').style.vi sibility = 'hidden'; }
}
</SCRIPT>
Nov 19 '05 #5

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

Similar topics

1
7349
by: Kidus Yared | last post by:
I am having trouble with the cursor in a richtextbox for windows forms. After incerting a character between words in a sentence, as so: this.richTextBox1.Text = this.richTextBox1.Text.Insert(this.richTextBox1.SelectionStart, ""+'\u1200'); Than the curser moves to the beginning of the textbox unabeling the user to continue to insert characters or words where it was origanelly slected. My solution to this is to get the cursor back to...
0
2996
by: chris | last post by:
I'm using the code below to attempt to find out the absolute pixel position of an element inside an activex web browser control (axWebBrowser). This example uses the 'www.google.co.uk' web page and attempts to find the position of the editbox where the search critera is enetered. My problem I'm having is that the result is always near the element but never exact (in this case, the left co-ordinate seems to be 7 pixels to high).
2
12738
by: db55 | last post by:
I have multiple locations that I want to create views for each individual location. I am using a cursor to create the views for each location. So, the cursor grabs site #1 then <should> create view_site_#1, then grab site #2 and <should> create view_site_#2. For some reason it doesn't like the view name with the @site in it. Any ideas of how to get this done?
1
3177
by: GGG | last post by:
Neither go the way I want them to... Absolute doesn't get it right over multiple browsers. Relative puts it in the right place, but only the portion that it is "relative" the style, #wleMenu, is running. Holding the cursor over any portion OUTSIDE of this block is not registering. Mozilla doesn't do anything, IE will fire off an error, when I go past "the zone" with "object required" (like the scipting isn't even there) I have the...
16
28066
Frinavale
by: Frinavale | last post by:
I am just wondering if it is possible to determine where the cursor is located within an <input type='text'> element using JavaScript? I'd like to write a snippet of code that will move to the focus to the next text box when the user has pressed the left arrow key and the cursor location has hit the text box's maxLength. Likewise I'd like the focus to move to the previous text box when the user has pressed the right arrow key (or...
1
1610
by: bluepiper | last post by:
Im using VB6. On rowcolchange event of may datagrid, im using the Frame caption to get the selected data. The problem is when I select the data on the grid. Its not showing the absolute position, still the first record. This is my code: Private Sub dgUser_RowColChange(LastRow As Variant, ByVal LastCol As Integer) Dim deUser As ADODB.Recordset AdvantageEnvironment.cmdUsers Set deUser = AdvantageEnvironment.rscmdUsers
3
3459
by: mckbill | last post by:
Is there a way I can direct the cursor to a specific field (variable) in a form by typing the field name while in form view? I have a form with many fields, and it would be nice if there were some method, similar to FIND RECORD (e.g., CTL + F ), where a dialog box would pop up and let me enter the field name, and then jump the cursor to that location. I currently do my edits by locating a record to be changed by ID using CTL+F and...
4
1903
by: Jonathan Sion | last post by:
Hi, I dont think this one is too dificult: i wish to show a windows form , its upper left corner would be right where the mouse is right now, (sort of like a popup menu) what i do is is something like: dim loc as Point = Cursor.Position myForm..SetDesktopLocation(loc .X, loc .Y) myForm.Show
2
15053
by: Adam Right | last post by:
Hi All, I'm developping a site using VS2008 (c#) on IIS 6.0. In my application images are not shown by the image control, they are in the web server machine and the main folder path is E:\PICTURES. If I set the ImageURL property in the code and set it to the absolute path of the image, it doesn't show. Is it possible to set ImageUrl property for absolute path of a image file,
0
8268
marktang
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...
0
8707
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, 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...
0
8641
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
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,...
0
8510
tracyyun
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...
0
5575
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();...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
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
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.