Pobieranie pozycji kursora myszy

Bardzo prosty kod służący do pobierania pozycji kursora myszy w javascript. Może komuś się przyda 😉

		<title>Get Mouse Coordinates</title>

		<script language="javascript">
			var divObj;

			* capture mousemove event, this statement will cause browser to
			* call getMouseCoordites function each time mouse moves

			*identify which event is supported
			* Based on that collect pageX and pageY properties of the event object
			* pageX and pageY gets the X and Y cursor coordinates
			function getMouseCoordinates(event){
				ev = event || window.event;
				divObj.innerHTML = "Mouse X:"+ev.pageX + " Mouse Y:"+ev.pageY;

			//assign the mouseCoord Object to divObj
			function loadDiv(){
				divObj = document.getElementById("mouseCoord");

	<body onLoad="loadDiv()">
		<div id="mouseCoord">Mouse Coordinates position will be displayed here.

Przykład http://darkgl.pl/mousecords.html

Dodaj komentarz