Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Absolute cursor location

Reply
Thread Tools

Absolute cursor location

 
 
=?Utf-8?B?U2lkIFMu?=
Guest
Posts: n/a
 
      12-08-2004
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

 
Reply With Quote
 
 
 
 
Lars Netzel
Guest
Posts: n/a
 
      12-08-2004
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." <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2lkIFMu?=
Guest
Posts: n/a
 
      12-08-2004
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." <(E-Mail Removed)> skrev i meddelandet
> news:(E-Mail Removed)...
> > 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
> >

>
>
>

 
Reply With Quote
 
Lars Netzel
Guest
Posts: n/a
 
      12-08-2004
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." <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed)...
> 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." <(E-Mail Removed)> skrev i meddelandet
>> news:(E-Mail Removed)...
>> > 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
>> >

>>
>>
>>



 
Reply With Quote
 
Ben Amada
Guest
Posts: n/a
 
      12-09-2004
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:hidden;
FONT:10pt comic sans ms; BORDER-LEFT:black 2px solid;
WIDTH:200px; PADDING-TOP:7px; BORDER-BOTTOM:black 2px solid;
POSITION:absolute; TOP:800px; HEIGHT:120px;
TEXT-ALIGN:center; z-index:1; background-image:
url('images/winmsg_back.gif'); " />


====== Call to Javascript =======
<span id="win1" onmouseover="richToolTip('Test Message',event);"
onmouseout="hideToolTip();" ><img src=images/awesome.gif height=35 width=35
/></span>


====== Javascript =======
<SCRIPT language=JavaScript>
function richToolTip(WinMsg, e)
{
var xCoord = 0;
var yCoord = 0;
var oScreenWidth = 0;
var oScreenHeight = 0;
var myElement;

if (document.layers)
{
// old Netscape versions
myElement = document.divWinMsg;
if ((myElement == null) || (myElement == "undefined"))
{ myElement = document.getElementById('divWinMsg'); }

oScreenWidth = window.innerWidth;
oScreenHeight = window.innerHeight;

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.getElementById('divWinMsg');

if (myElement != null && myElement != "undefined")
{
oScreenWidth = document.body.clientWidth;
oScreenHeight = document.body.clientHeight;

xCoord = e.clientX + document.body.scrollLeft +
document.documentElement.scrollLeft + 15;
yCoord = e.clientY + document.body.scrollTop +
document.documentElement.scrollTop + 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.innerHTML = WinMsg;
if (document.layers)
{

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

if ((myElement.style.visibility == null) ||
(myElement.style.visibility == "undefined"))
{ myElement.visibility = 'visible'; }
else
{ myElement.style.visibility = 'visible'; }

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

function hideToolTip()
{
if (document.layers)
{
// old Netscape versions
var myElement = document.divWinMsg;
if ((myElement == null) || (myElement == "undefined"))
{ myElement = document.getElementById('divWinMsg'); }
if ((myElement.style.visibility == null) ||
(myElement.style.visibility == "undefined"))
{ myElement.visibility = 'hidden'; }
else
// IE and newer versions of Netscape
{ myElement.style.visibility = 'hidden'; }
}
else
{ document.getElementById('divWinMsg').style.visibil ity = 'hidden'; }
}
</SCRIPT>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to tell if cursor is sqlite.Cursor or psycopg2.Cursor dmaziuk Python 3 01-25-2011 04:52 AM
How does one get an absolute absolute file path? James Byrne Ruby 3 09-14-2010 06:02 PM
Location, location, location =?Utf-8?B?VHJhY2V5?= Wireless Networking 2 02-17-2007 08:37 PM
Declare Cursor error while implementing SCROLL CURSOR invy C Programming 4 12-28-2006 02:35 PM
Changing DEFAULT cursor to WAIT cursor in ASP =?Utf-8?B?VG9tYXMgS2VwaWM=?= ASP .Net 1 04-05-2005 07:42 PM



Advertisments