Advertisement
cdsatrian

coordinat on image

Sep 19th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.17 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3.   <head>
  4.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  5.     <style type="text/css">
  6.     html {
  7.       border: none;
  8.       overflow: auto;
  9.     }
  10.     body {
  11.       margin: 0;
  12.       padding: 0;
  13.       font-family:verdana;
  14.       font-size:9px;
  15.     }
  16.     img {
  17.       position: absolute;
  18.       top: 0%;
  19.       left: 0%;
  20.       margin:30px;
  21.     }
  22.     </style>
  23.     <title>jQuery - Mouse Coordinates Over Image</title>
  24.   </head>
  25.   <body>
  26.     koordinat x <input type="text" id="x" name="x" value="0" /> : y <input type="text" id="y" name="y" value="0" />
  27.     <img src="http://inapcache.boston.com/universal/site_graphics/blogs/bigpicture/flight_2012/bp1.jpg">
  28.     <script type="text/javascript">
  29.     $('img').click(function(event){
  30.       var x = event.pageX - this.offsetLeft;
  31.       var y = event.pageY - this.offsetTop;
  32.       alert('X: '+x+'  Y:'+y);
  33.     });
  34.     $('img').mousemove(function(event){
  35.       var x = event.pageX - this.offsetLeft;
  36.       var y = event.pageY - this.offsetTop;
  37.       $('#x').val(x);      
  38.       $('#y').val(y);
  39.     });
  40.     </script>
  41.   </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement