JS gets the mouse coordinates, obtains the mouse pixel point example

Source: Internet
Author: User

  After running the code to move the position of the mouse at will, you can display the mouse coordinates, do not occupy system resources

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 ">  <html xmlns=" http://www.w3.org/1999/xhtml ">  <head>  <title> JavaScript gets mouse coordinates </title>  <meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 "/>  <style type=" text/css ">  tip {  width:200px;  the border:2px #ddd; nbsp 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>  </head>  <body>  <div id= "MJS" class= "tip "> Source Enthusiasts </div>  <div id=" test "style=" Width:1000px;height:1000px;background: #ccc; "Onmousemove=" Test (event) "></div>  </body>  </html>      [Ctrl + a full election note: If you 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.