Toto je starší verze dokumentu!
<!DOCTYPE html> <html lang="cs"> <head> <meta charset="utf-8" /> <title>Postřeh</title> <style> body { background-color: #e0e0e0; display: flex; justify-content: center; align-items: center; height: 100vh; } #herni_plocha { background-color:red; width: 300px; height:300px; } </style> <script> /* <![CDATA[ */ /* Sem prijde javascript kod */ function mys(event){ const rect = event.target.getBoundingClientRect(); // x position within the element. const x = event.clientX - rect.left; const y = event.clientY - rect.top; console.log(x + " " + y) } setTimeout( function(){ document.getElementById('herni_plocha').addEventListener("mousemove", mys); },0 ) /* ]]> */ </script> </head> <body> <div id="herni_plocha"></div> </body> </html>