Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: Event
Source: JSObjects/DeviceMotionEvent.cs
MDN Reference: DeviceMotionEvent on MDN
The DeviceMotionEvent interface provides web developers with information about the speed of changes for the device's position and orientation. https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent
| Signature | Description |
|---|---|
DeviceMotionEvent(SpawnJSObjectReference _ref) |
Default deserialize constructor |
| Property | Type | Access | Description |
|---|---|---|---|
Acceleration |
DeviceMotionXYZ |
get | An object giving the acceleration of the device on the three axis X, Y and Z. Acceleration is expressed in m/s². |
AccelerationIncludingGravity |
DeviceMotionXYZ |
get | An object giving the acceleration of the device on the three axis X, Y and Z with the effect of gravity. Acceleration is expressed in m/s². |
RotationRate |
DeviceMotionAlphaBetaGamma |
get | An object giving the rate of change of the device's orientation on the three orientation axis alpha, beta and gamma. Rotation rate is expressed in degrees per seconds. |
Interval |
double |
get | A number representing the interval of time, in milliseconds, at which data is obtained from the device. |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<DeviceMotionEvent>(...)or constructornew DeviceMotionEvent(...)
window.addEventListener("devicemotion", (event) => {
console.log(`${event.acceleration.x} m/s2`);
});JavaScript (MDN):
window.addEventListener("devicemotion", (event) => {
console.log(`${event.acceleration.x} m/s2`);
});C# (SpawnDev.SpawnJS):
// Requires: builder.Services.AddSpawnJSRuntime();
// Inject SpawnJSRuntime in your component or service:
// [Inject] SpawnJSRuntime JS { get; set; }
window.addEventListener("devicemotion", (event) => {
Console.WriteLine($"{event.Acceleration.x} m/s2");
});