JavaScript DHTML/Event/Mouse

Материал из Web эксперт
Перейти к: навигация, поиск

"button" Example

   <source lang="html4strict">

   

<html> <body> <script language="JavaScript">

   function function1() {
       var m = window.event.button;
       if (m == 1) { 
           alert("The left button has been pressed"); 
       } else if (m == 2) { 
           alert("The right button has been pressed"); 
       }
   }

</script>

Press on mouse while on top of this blue box.

</body> </html>


 </source>
   
  


Get X/Y screen position (IE)

   <source lang="html4strict">
 

<html> <head> <title>X/Y Marks the Spot</title> <script type="text/javascript"> function mouseDown(nsEvent) {

 var theEvent = nsEvent ? nsEvent : window.event;
 var locString = "X = " + theEvent.screenX + " Y = " + theEvent.screenY;
 alert(locString);

} document.onmousedown=mouseDown; </script> </head> <body> </body> </html>


 </source>
   
  


Mouse wheel Delta

   <source lang="html4strict">

   

<html> <body>

Move mouse wheel on top of the image to check the wheel delta

<img id="yourimage"

    src="http://www.wbex.ru/style/logo.png" 
    onmousewheel="alert("Wheel Delta: " + event.wheelDelta);">

</body> </html>


 </source>