getDeviceOrientation

Category Sensors

Provides web developers with information from the physical orientation of the device running the web page.

Demo

{
  "isSupported": false,
  "isAbsolute": false,
  "alpha": 0,
  "beta": 0,
  "gamma": 0
}

Usage

<script>
	import { getDeviceOrientation } from '@sv-use/core';
 
	const deviceOrientation = getDeviceOrientation();
</script>
Type definitions
import type { CleanupFunction } from '../../__internal__/types.js';
type GetDeviceOrientationOptions = {
    /**
     * Whether to auto-cleanup the event listener or not.
     *
     * If set to `true`, it must run in the component initialization lifecycle.
     * @default true
     */
    autoCleanup?: boolean;
};
type GetDeviceOrientationReturn = {
    readonly isSupported: boolean;
    /** Whether or not the device is providing orientation data absolutely or not. */
    readonly isAbsolute: boolean;
    /** The motion of the device around the z axis, express in degrees with values ranging from 0 (inclusive) to 360 (exclusive). */
    readonly alpha: number;
    /** The motion of the device around the x axis, express in degrees with values ranging from -180 (inclusive) to 180 (exclusive). */
    readonly beta: number;
    /** The motion of the device around the y axis, express in degrees with values ranging from -90 (inclusive) to 90 (exclusive). */
    readonly gamma: number;
    /**
     * Cleans up the event listener.
     * @note Is called automatically if `options.autoCleanup` is set to `true`.
     */
    cleanup: CleanupFunction;
};
/**
 * Provides web developers with information from the physical orientation of the device running the web page.
 * @see https://svelte-librarian.github.io/sv-use/docs/core/sensors/get-device-orientation
 */
export declare function getDeviceOrientation(options?: GetDeviceOrientationOptions): GetDeviceOrientationReturn;
export {};

Sources