JS get mouse coordinates, get mouse pixel points sample _javascript tips

Source: Internet
Author: User
JS get the mouse coordinates, get the typical example of the mouse pixel, run this page, move the mouse at will, the location of the mouse can be displayed in due time, do not occupy the system resources.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <title>javascript get mouse coordinates </title> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <style type=" Text/css "> Tip {width:200px; border:2px solid #ddd; padding:8px; Background: #f1f1f1; Color: #666; } </style> <script type= "Text/javascript" > Function Mousepos (e) {var x,y; var e = e| | window.event; return {x:e.clientx+document.body.scrollleft+document.documentelement.scrollleft, y:e.clienty+ Document.body.scrolltop+document.documentelement.scrolltop}; }; function Test (e) {document.getElementById ("MJs"). InnerHTML = Mousepos (e). x+ ', ' +mousepos (e). Y; }; </script> </pead> <body> <div id= "MJS" class= "tip" > Source enthusiasts </div> <div id= "test" onmous Emove= "Test (event)" ></div> </body></ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.