(046)javascript_event_mouseevent

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     <title>EVENT</title>
 6     <style type="text/css">
 7         #myDiv {
 8             width: 100px;
 9             height: 100px;
10             background: blue;
11             position: absolute;
12         }
13     </style>
14     <script type="text/javascript">
15 
16         document.onmousemove = function(ev) {
17 
18             var myDivNode = document.getElementById("myDiv");
19             var oEvent = ev || event;
20             var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
21             var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
22 
23             myDivNode.style.left = oEvent.clientX + scrollLeft + "px";
24             myDivNode.style.top = oEvent.clientY + scrollTop + "px";
25             
26         };
27 
28     </script>
29 </head>
30 
31 <body style="height:2000px;">
32 
33     <div id="myDiv"></div>
34 
35 </body>
36 </html>

 

posted @ 2014-03-23 11:09  雪中飞雁  阅读(52)  评论(0)    收藏  举报