Js to get the coordinates of the mouse

Source: Internet
Author: User

Event. clientX sets or obtains the x coordinates of the cursor position relative to the client area of the window. The client area does not include the control and scroll bar of the window.
Event. clientY sets or obtains the y coordinate of the cursor position relative to the client area of the window. The client area does not include the control and scroll bar of the window.
Event. offsetX is used to set or obtain the x coordinate of the cursor position relative to the object that triggers the event.
Event. offsetY is used to set or obtain the y coordinate of the cursor position relative to the object that triggers the event.
Event. screenX is used to set or obtain the x coordinates of the cursor position relative to the user's screen.
Event. screenY is used to set or obtain the y coordinate of the cursor position relative to the user's screen.
Event. clientX and event. clientY are usually used!
Example:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
</HEAD>
<Script type = "text/javascript">

Function bijiao (name ){
Var json = {'username': 'A', 'Password': 'bb', 'age': '5 '};
Var json1 = {'username': 'aa1', 'Password': 'bb', 'age': '6 '};
Var map = new Array ();

// For (var I = 0; I <json. length; I ++ ){
For (var key in json ){
// Alert (key + ':' + json [key]);
For (var key1 in json1 ){
If (name = key ){
If (key = key1 ){
If (json [key] = json1 [key1]) {
// Alert (key + "=" + key1 + "same attribute value ");
Return "";
} Else {
// Alert (key + "=" + key1 + "different attribute values ");
Return json1 [key1];
}
}}
}
}
//}

}
// Alert (json. username );
// Map. put ();
Function aa (obj, flag, iwidth ){
Var oldvalue = bijiao (obj. name)
If (oldvalue! = ''){
Var my_tips = document. all. mytips;
// Var my_tips = document. getElementById ("myadiv ");
My_tips.innerHTML = oldvalue;
My_tips.style.display = "";
My_tips.style.width = iwidth;
My_tips.style.left = event. clientX + 120 + document. body. scrollLeft;
My_tips.style.top = document. body. scrollTop + event. clientY
If (! Flag ){
My_tips.style.display = "none ";
}
} Else {
}
}
</Script>
<BODY>

<Form>
<Div style = "width: 999px; height: auto; border-left: solid 1px # bae1f8; border-right: solid 1px # bae1f8;
Overflow: hidden; ">
<! -- Cannot be removed -->
<Div class = "patentindex" id = "mytips" style = "border-right: gray 1px solid; border-top: gray 1px solid;
Display: none; filter: progid: DXImageTransform. Microsoft. Shadow (color = #999999, direction = 135, strength = 3 );
Left: 0px; border-left: gray 1px solid; border-bottom: gray 1px solid; position: absolute;
Background-color: # ffffff; text-align: left; ">
<! ---->
</Div>
Username: <input type = "text" id = "username" name = "username" onmousemove = "aa (this, 1,200)" onmouseout = "aa (this, 0,200) "/> <br>
Password: <input type = "text" id = "password" name = "password" onmousemove = "aa (this, 1,200)" onmouseout = "aa (this, 0,200) "/> </br>
Age: <input type = "text" id = "age" name = "age" onmousemove = "aa (this, 1,200)" onmouseout = "aa (this, 0,200) "/>
</Form>
</BODY>
</HTML>
Example 2:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
</HEAD>
<Script type = "text/javascript">

Function bijiao (name ){
Var json = {'username': 'A', 'Password': 'bb', 'age': '5 '};
Var json1 = {'username': 'aa1', 'Password': 'bb', 'age': '6 '};
Var map = new Array ();

// For (var I = 0; I <json. length; I ++ ){
For (var key in json ){
// Alert (key + ':' + json [key]);
For (var key1 in json1 ){
If (name = key ){
If (key = key1 ){
If (json [key] = json1 [key1]) {
// Alert (key + "=" + key1 + "same attribute value ");
Return "";
} Else {
// Alert (key + "=" + key1 + "different attribute values ");
Return json1 [key1];
}
}}
}
}
//}

}
// Alert (json. username );
// Map. put ();
Function aa (obj, flag, iwidth ){

Var top = obj. offsetTop;
Var left = obj. offsetLeft;
Var objWidth = obj. offsetWidth;
Var objHeight = obj. offsetHeight;
Var oldvalue = bijiao (obj. name)

If (oldvalue! = ''){
Var my_tips = document. all. mytips;
// Var my_tips = document. getElementById ("myadiv ");
My_tips.innerHTML = oldvalue;
My_tips.style.display = "";
My_tips.style.width = iwidth;
// My_tips.style.left = event. clientX + 120 + document. body. scrollLeft;
// My_tips.style.top = document. body. scrollTop + event. clientY-26
My_tips.style.left = left + objWidth;
My_tips.style.top = top;
If (! Flag ){
My_tips.style.display = "none ";
}
} Else {
}
}
</Script>
<BODY>

<Form>
<Div style = "width: 999px; height: auto; border-left: solid 1px # bae1f8; border-right: solid 1px # bae1f8;
Overflow: hidden; ">
<! -- Cannot be removed -->
<Div class = "patentindex" id = "mytips" style = "border-right: gray 1px solid; border-top: gray 1px solid;
Display: none; filter: progid: DXImageTransform. Microsoft. Shadow (color = #999999, direction = 135, strength = 3 );
Left: 0px; border-left: gray 1px solid; border-bottom: gray 1px solid; position: absolute;
Background-color: # ffffff; text-align: left; ">
<! ---->
</Div>
Username: <input type = "text" id = "username" name = "username" onmousemove = "aa (this, 1,200)" onmouseout = "aa (this, 0,200) "/> <br>
Password: <input type = "text" id = "password" name = "password" onmousemove = "aa (this, 1,200)" onmouseout = "aa (this, 0,200) "/> </br>
Age: <input type = "text" id = "age" name = "age" onmousemove = "aa (this, 1,200)" onmouseout = "aa (this, 0,200) "/>
</Form>
</BODY>
</HTML>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.