Window dimensions
Allows tracking window dimensions with Events and Stores.
INFO
Uses Window: resize event, Window: scroll event, Window: requestAnimationFrame under the hood
Usage
All you need to do is to create an integration by calling trackWindowDimensions with an integration options:
setup: after this Event all listeners will be installed, and the integration will be ready to use; it is required because it is better to use explicit initialization Event in the application.teardown?: after this Event all listeners will be removed, and the integration will be ready to be destroyed.
ts
import { trackWindowDimensions } from '@withease/web-api';
const {
$scrollY,
$scrollX,
$innerWidth,
$innerHeight,
$outerWidth,
$outerHeight,
$screenLeft,
$screenTop,
} = trackWindowDimensions({
setup: appStarted,
});Returns an object with:
$scrollY: Store with the current scroll position on the Y-axis$scrollX: Store with the current scroll position on the X-axis$innerWidth: Store with the current width of the viewport$innerHeight: Store with the current height of the viewport$outerWidth: Store with the current width of the entire window$outerHeight: Store with the current height of the entire window$screenLeft: Store with the current left position of the screen$screenTop: Store with the current top position of the screen
Live demo
Let us show you a live demo of how it works. The following demo displays a $scrollX, $innerWidth, $innerHeight, $outerWidth, $outerHeight, $screenLeft, and $screenTop values of the current window dimensions. Scroll, resize, and move the window to see how it works.