BrowserEvent
Convenience class to detect browser events on the browser window object.
This class has methods that allow you to pass a callback function to run for specific events. These events include load, resize, wheel, deviceorientation, devicemotion, unload.
JLS.events.BrowserEvent
new BrowserEvent()
let browserEvent = new BrowserEvent()
// Detecting a browser event
browserEvent
.onLoad(() => {
// do something
})
.onResize(() => {
// do something
})
// Choosing not to listen to auto-registered events
browserEvent.unsubscribe('devicemotion')
Members
screen
The browser window object.
registeredEvents
An array list of the registered events.
callbacks
A object containing all the registered callbacks. The object property namesare the event types.
Callbacks
onLoad(cb)
A resource and its dependent resources have finished loading.
| Name | Type | Description |
|---|---|---|
| cb | function | A function that is passed to run when the event is triggered. |
onResize(cb)
The document view has been resized.
| Name | Type | Description |
|---|---|---|
| cb | function | A function that is passed to run when the event is triggered. |
onWheel(cb)
A wheel button of a pointing device is rotated in any direction.
| Name | Type | Description |
|---|---|---|
| cb | function | A function that is passed to run when the event is triggered. |
onDeviceOrientation(cb)
The orientationchange event is fired when the orientation of the device has changed.
| Name | Type | Description |
|---|---|---|
| cb | function | A function that is passed to run when the event is triggered. |
onDeviceMotion(cb)
The devicemotion event is fired at a regular interval and indicates the amount of physical force of acceleration the device is receiving at that time. It also provides information about the rate of rotation, if available.
| Name | Type | Description |
|---|---|---|
| cb | function | A function that is passed to run when the event is triggered. |
onUnload(cb)
The document or a dependent resource is being unloaded.
| Name | Type | Description |
|---|---|---|
| cb | function | A function that is passed to run when the event is triggered. |
Methods
unsubscribe(event)
Detaches keydown and keyup listeners to the key and stops listening for events. Returns true if successful.
| Name | Type | Description |
|---|---|---|
| event | string | The event to unsubscribe and stop listening for. Options: load, resize, wheel, deviceorientation, devicemotion, unload. |
init()
Automatically called on object contruction, this method intializes the BrowserEvent by setting the window screen.