domEventgetMouseButton.jsline 32
Static Methods
getMouseButton(mouseEvent)getMouseButton.jsline 32
Normalize mouse event's button attributes.
PARAMETERS
Name Type Description mouseEvent
MouseEvent
The mouse event object want to know.
RETURNS:
{number
} - The value of meaning which button is clicked?
getMousePosition(position, relativeElement)getMousePosition.jsline 20
Get mouse position from mouse event
PARAMETERS
Name Type Description position
MouseEventobjectArray.<number>
mouse position object
relativeElement
HTMLElement
HTML element that calculate relative
positionRETURNS:
{Array.<number>
} - mouse position
getTarget(e)getTarget.jsline 13
Get a target element from an event object.
PARAMETERS
Name Type Description e
Event
event object
RETURNS:
{HTMLElement
} - target element
off(element, types, handler)off.jsline 39
Unbind DOM events
If a handler function is not passed, remove all events of that type.PARAMETERS
Name Type Description element
HTMLElement
element to unbind events
types
stringobject
Space splitted events names or eventName:handler object
handler
[ function ]
handler function
EXAMPLES
// Following the example of domEvent#on // Unbind one event from an element. off(div, 'click', toggle); // Unbind multiple events with a same handler from multiple elements at once. // Use event names splitted by a space. off(element, 'mouseenter mouseleave', changeColor); // Unbind multiple events with different handlers from an element at once. // Use an object which of key is an event name and value is a handler function. off(div, { keydown: highlight, keyup: dehighlight }); // Unbind events without handlers. off(div, 'drag');
on(element, types, handler, context)on.jsline 44
Bind DOM events.
PARAMETERS
Name Type Description element
HTMLElement
element to bind events
types
stringobject
Space splitted events names or eventName:handler object
handler
functionobject
handler function or context for handler method
context
[ object ]
context - context for handler method.
EXAMPLES
const div = document.querySelector('div'); // Bind one event to an element. on(div, 'click', toggle); // Bind multiple events with a same handler to multiple elements at once. // Use event names splitted by a space. on(div, 'mouseenter mouseleave', changeColor); // Bind multiple events with different handlers to an element at once. // Use an object which of key is an event name and value is a handler function. on(div, { keydown: highlight, keyup: dehighlight }); // Set a context for handler method. const name = 'global'; const repository = {name: 'CodeSnippet'}; on(div, 'drag', function() { console.log(this.name); }, repository); // Result when you drag a div: "CodeSnippet"
once(element, types, handler, context)once.jsline 21
Bind DOM event. this event will unbind after invokes.
PARAMETERS
Name Type Description element
HTMLElement
HTMLElement to bind events.
types
stringobject
Space splitted events names or
eventName:handler object.handler
functionobject
handler function or context for handler method.
context
[ object ]
context object for handler method.
preventDefault(e)preventDefault.jsline 12
Prevent default action
PARAMETERS
Name Type Description e
Event
event object
stopPropagation(e)stopPropagation.jsline 12
Stop event propagation.
PARAMETERS
Name Type Description e
Event
event object