
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Library to configure and listen to device motion changes based on defined delta variations for each angle
Library to configure and listen to device motion changes based on defined delta variations for each angle.
Why? Though you can listen to the device orientation event, you will receive long floating numbers for each angle that is affected when the user moves the device. Creating deltas listeners you can easily configure actions for specific variation points.
Include the script inside the dist folder in your project:
<script src="dist/deltas.js"></script>
or install it running npm install --save deltas
and import it:
import { Listener } from delta;
let listener = new Listener({
delta: 15,
action(delta, angle) {
// do something...
}
});
When setting a delta you're instructing the listener to fire an action each time an angle varies proportionally. This means that if you set a delta to 10
, the action will be fired when the orientation angle is 10
, 20
, 30
, etc.
Each action receives two arguments, the depth of the delta reached and the angle. If you set a delta to 10
, the action will be called with 1
when the orientation angle is 10
, with 2
when the orientation angle is 20
, etc.
The second argument is the angle which can be alpha, beta or gamma. These three come from the spec fo the device orientation event.
The alpha swirls around the z axis. Imagine a phone is set on a flat surface, like a table, and you rotate without lifting it, that's the alpha angle and it goes from 0
to 360
.
The beta angle swirls around the x axis, which is the one that crosses the device from side to side and goes from -180
to 180
, being zero when is to rest horizontally.
The gamma angle swirls around the y axis, which is the one that crosses the device from top to bottom and goes from -90
to 90
, being zero when is to rest horizontally.
Orientation angles can be hard to figure, I recommend this MDN article about them: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Orientation_and_motion_data_explained
With deltas listeners you can execute actions every time the angle varies an amount of degrees.
import { Listener } from delta;
let listener = new Listener({
delta: 10,
action(delta, angle) {
// this will be called for each angle
}
});
But you can also just listen to one specific angle.
let listener = new Listener({
alpha: {
delta: 10,
action(delta, angle) {
// this will be called only for alpha angle
}
}
});
You can pass a default delta and action, and add just a special action.
let listener = new Listener({
delta: 10,
action(delta, angle) {
// this will get called for beta and gamma
},
alpha: {
action(delta, angle) {
// this will be called only for alpha angle
}
}
});
Or add just a special delta.
let listener = new Listener({
delta: 10,
action(delta, angle) {
// this will get called for all angles
},
alpha: {
delta: 25
}
});
Or customize all!
let listener = new Listener({
alpha: {
delta: 10,
action(delta, angle) {
// this will be called only for alpha angle
}
},
beta: {
delta: 20,
action(delta, angle) {
// this will be called only for beta angle
}
},
gamma: {
delta: 30,
action(delta, angle) {
// this will be called only for gamma angle
}
}
});
Deltas listeners were tested in latest Chrome mobile, latest Opera mini and Safari mobile 10 so further. The script is also written in ES2015 which works well on modern mobile browsers but would need transpiling for older versions.
If you create fun stuff with it, let me know!
MIT License
FAQs
Library to configure and listen to device motion changes based on defined delta variations for each angle
The npm package deltas receives a total of 3 weekly downloads. As such, deltas popularity was classified as not popular.
We found that deltas demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.