New Mouse Events
click event still occurs when you press and release the mouse button while the cursor is on a specific object. But the
mousedown events are more specific than a general click. They reflect separate steps in the "click process." As with the new keyboard events, your scripts can now take one action when the mouse button is pressed atop an object, and another action when the button is released. As you would expect, the
dblclick event occurs when you double click an object that supports the event.
Another new mouse-related event is
mousemove, which deals with mouse movement rather than mouse clicks. With this event, you can find out when the cursor is moved, and possibly react to specific movements. For example, you could use the
onmousemove event handler to let the user drag specific elements from one place to another.
The following example demonstrates the use of the
modifiers property. It displays an alert dialog box when you click down the mouse button anywhere in the document with the Ctrl key pressed. Here it is:
Try it out by pressing the Ctrl key, and clicking down the mouse button anywhere on the page. A dialog box will pop up if you're using Netscape Navigator 4.0x. The script uses the bitwise AND operator to check if the contstant value (
Event.CONTROL_MASK) is a component of the
modifiers property. Here's a complete list of the supported modifier constants:
Be sure to read the related columns at the Dynamic HTML Lab for more demonstrations:
Created: December 16, 1997
Revised: January 11, 1997