npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

orientation.js

v1.0.0

Published

A js library extend on DeviceOrientation Event

Downloads

3

Readme

orientation.js NPM version

处理重力感应,通过监听 deviceorientationorientationchange 事件。

  • deviceorientation 的回调函数参数 DeviceOrientationEvent 进行封装,增加了一些更便于使用的属性,
  • 统一了 iOSAndroid 的差异
  • 处理了横屏竖屏的情况

DEMO

安装

npm install --save orientation.js

使用

支持 AMD、CMD 或者直接引入。

var Orientation = require('orientation.js')

var ori = new Orientation({
    initForwardSlant: 45, // 可选,初始向前倾斜度
    onChange: function (e) {
        console.log(e)
    }
})
ori.init()

介绍

配置项

  • initForwardSlant Number 可选

    前后倾斜度基准值

  • onChange Function(event)

    监听重力感应的回调函数。在 DeviceOrientationEvent 的基础上增加了:

    • lon Number [0, 360]

      水平坐标。初始时的位置为 0

    • lat Number [-270, 90]

      垂直坐标。当手机竖直时,lat 为 0

    • offsetLon Number

      相对上一次回调时,水平坐标的偏移量

    • offsetLat Number

      相对上一次回调时,垂直坐标的偏移量

    • leftRotate/rightRotate Number [-180, 180]

      向左/右旋转偏移量

    • leftSlant/rightSlant Number [-90, 90]

      向左/右倾斜偏移量

    • isLeft/isRight Boolean

      是否向左/右倾斜

    • forwardSlant/backwardSlant Number [-180, 180]

      向前/后倾斜偏移量

    • isForward/isBackward Boolean

      是否向前/后倾斜

    • relativeForwardSlant/relativeBackwardSlant Number [-180, 180]

      相对于初始位置或 initForwardSlant 的前/后倾斜偏移量

    • isRelativeForward/isRelativeBackward Boolean

      相对于初始位置或 initForwardSlant 的是否前/后倾斜

实例方法

init

初始化,开始监听事件

pause

不触发 onChange

continue

解除 pause 状态

destory

销毁监听事件

启示

感谢 @shrekshrek 的 https://github.com/shrekshrek/orienter

许可

MIT