
CHAPTER 4: User-Interface Tools Event handling 153
MouseEvent object
This type of object is passed to your registered event handler when a mouse-input event occurs. The
properties reflect the button and modifier-key state and pointer position at the time the event was
generated.
In the case of nested elements, mouse event types are always targeted at the most deeply nested element.
Ancestors of the targeted element can use bubbling to obtain notification of mouse events which occur
within its descendent elements.
MouseEvent object properties
In addition to the properties defined for UIEvent base class, a mouse event has these properties. All
properties are read-only.
altKey
Boolean When true, the ALT key was active. Value is undefined if the
keyIdentifier is for a modifier key.
button
Number Which mouse button changed state.
0—The left button of a two- or three-button mouse or the one button
on a one-button mouse, used to activate a UI button or select text.
1— The middle button of a three-button mouse, or the mouse wheel.
2—The right button, used to display a context menu, if present.
Some mice may provide or simulate more buttons, and values higher than
2 represent such buttons.
clientX
clientY
Number The horizontal and vertical coordinates at which the event occurred
relative to the target object. The origin is the top left of the control or
window, inside any border decorations.
ctrlKey
Boolean When true, the CTRL key was active. Value is undefined if the
keyIdentifier is for a modifier key.
detail
Number Details of the event, which vary according to the event type. For the
click, mousedown, and mouseup events, the value is 1 for a single click, or
2 for a double click.
metaKey
Boolean When true, the META or COMMAND key was active. Value is undefined if the
keyIdentifier is for a modifier key.
relatedTarget
Object X For a mouseover event, the UI element the pointer is leaving, if any.
X For a mouseout event, the UI element the pointer is entering, if any.
X Otherwise undefined.
screenX
screenY
Number The horizontal and vertical coordinates at which the event occurred
relative to the screen.
Komentáře k této Příručce