# Class: WindowEvents

## WindowEvents

#### new WindowEvents($window [, throttleDelay])

  Window events handler

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `$window` | HTMLElement |  |  | DOM object on which the events will be checked
  `throttleDelay` | Number | <optional> | -1 | Throttle delay in ms. If < 0, it use requestAnimationFrame

  ##### Example

      let w = new WindowEvents( window );

      or to change throttle delay :

      let w = new WindowEvents( window, 150 );

      let callback = ( { windowInfo, scrollInfo, documentInfo, viewportInfo }, type, event ) => {};

      w.register( callback, 'resize' ); // type = 'resize', 'scroll' or undefined for both
      w.remove( callback, 'resize' );

      // Force refresh of all registered function
      w.refresh( 'scroll' );

      // Force the computing scroll position window and document size
      w.update();

      // Call the function
      w.get( callback );

      // Tools
      { top, left } = w.scrollInfo;
      { width, height } = w.windowInfo;
      { width, height } = w.documentInfo;
      { top, left, bottom, right, width, height } = w.viewportInfo;

### Members

#### documentInfo :Object

  { width, height }

  ##### Type:

  - Object

#### scrollInfo :Object

  { top, left }

  ##### Type:

  - Object

#### viewportInfo :Object

  The viewport is the displayed part of the document.
  So, its top and left are the scroll position and its width and height are the window size.
  { top, left, bottom, right, width, height }

  ##### Type:

  - Object

#### windowInfo :Object

  { width, height }

  ##### Type:

  - Object

### Methods

#### get(callback)

  Call a function with the last stored positions and sizes

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | WindowEvents_Handler |

  ##### Returns:

  Type
    WindowEvents

#### refresh(type)

  Refresh all the registered functions

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `type` | String | resize | scroll | undefined (both)

  ##### Returns:

  Type
    WindowEvents

#### register(callback, type)

  Register a function on a type of event

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | WindowEvents_Handler |
  `type` | String | resize | scroll | undefined (both)

  ##### Returns:

  Type
    WindowEvents

#### remove(callback, type)

  Unregister a function for a type of event

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | WindowEvents_Handler |
  `type` | String | resize | scroll | undefined (both)

  ##### Returns:

  Type
    WindowEvents

#### update(type)

  Update all the stored data (window size, scroll position, ...)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `type` | String | resize | scroll | undefined (both)

  ##### Returns:

  Type
    WindowEvents

### Type Definitions

#### WindowEvents_Handler(info, eventType [, originalEvent])

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `info` | Object |  | ###### Properties
  Name | Type | Description
  --- | --- | ---
  `windowInfo` | Object | ###### Properties
  Name | Type | Description
  --- | --- | ---
  `width` | Number |
  `height` | Number |
  `scrollInfo` | Object | ###### Properties
  Name | Type | Description
  --- | --- | ---
  `top` | Number |
  `left` | Number |
  `documentInfo` | Object | ###### Properties
  Name | Type | Description
  --- | --- | ---
  `width` | Number |
  `height` | Number |
  `viewportInfo` | Object | ###### Properties
  Name | Type | Description
  --- | --- | ---
  `top` | Number |
  `left` | Number |
  `bottom` | Number |
  `right` | Number |
  `width` | Number |
  `height` | Number |
  `eventType` | String |  | resize | scroll | force
  `originalEvent` | Event | <optional> | if available

#### Search results