JavaScript DHTML/Event/Mouse

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

"button" Example

 
    
<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>
<div style="width:200; 
            height:200; 
            background-color:blue; 
            color:white;" 
     onmousedown="function1();">
Press on mouse while on top of this blue box.
</div>
</body>
</html>



Get X/Y screen position (IE)

  
<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>



Mouse wheel Delta

 
    
<html>
<body>
<p>
Move mouse wheel on top of the image to check the wheel delta
</p>
<img id="yourimage" 
     src="http://www.wbex.ru/style/logo.png" 
     onmousewheel="alert("Wheel Delta: " + event.wheelDelta);">
</body>
</html>