Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.42 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  4.         <title>Задание №2</title>
  5.         <script type="text/javascript" src="scripts/task8.js">
  6.         var div,
  7.         mousex,
  8.         mousey,
  9.         active=false;
  10.        
  11.     function start() {
  12.         div=document.getElementById("maindiv");
  13.         window.setInterval("run();", 5);
  14.     }
  15.  
  16.     function run() {
  17.         if (parseInt(div.style.top, 10)>mousey) {
  18.             //div.style.top=parseInt(div.style.top,10)-1;
  19.             div.style.top=mousey;
  20.         } else {
  21.             if (parseInt(div.style.top, 10)<mousey) {
  22.                //div.style.top=parseInt(div.style.top, 10)+1;
  23.                div.style.top=mousey;
  24.            }
  25.        }
  26.        
  27.        if (parseInt(div.style.left, 10)>mousex) {
  28.             //div.style.left=parseInt(div.style.left, 10)-1;
  29.             div.style.left=mousex;
  30.         } else {
  31.             if (parseInt(div.style.left, 10)<mousex) {
  32.                //div.style.left=parseInt(div.style.left, 10)+1;
  33.                div.style.left=mousex;
  34.            }
  35.        }
  36.    }  
  37.    
  38.    function move(event) {
  39.        window.mousex=event.clientX;
  40.        window.mousey=event.clientY;
  41.    }
  42.        </script>
  43.     </head>
  44.     <body onload="start();" onmousemove="move(event);">
  45.         <div style="z-index=2;" id="maindiv">Мельников</div>
  46.     </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement