mob-spy

1.0.4 • Public • Published

mob-spy

A super lightweight package for accurately detecting mobile device and orientation. (支持响应式)检测是否是移动端,超准超简便


Install

npm install mob-spy

Usage

普通用法

import Mob from "mob-spy";

const mob = new Mob();

// log true in PC, and log false in mobile/ipad/pad
console.log(mob.getIsPc);

// log the orientation of the screen when it is in mobile/ipad/pad
// portrait or landscape
console.log(mob.getOrientation);

响应式用法

import Mob from "mob-spy";

const mob = new Mob();

window.onresize = () => {
  mob.onWindowResize();

  // log true in PC, and log false in mobile/ipad/pad
  console.log(mob.getIsPc);

  // log the orientation of the screen when it is in mobile/ipad/pad
  // portrait or landscape
  console.log(mob.getOrientation);
};

// 或者
window.addEventListener("resize", () => {
  mob.onWindowResize();

  // log true in PC, and log false in mobile/ipad/pad
  console.log(mob.getIsPc);

  // log the orientation of the screen when it is in mobile/ipad/pad
  // portrait or landscape
  console.log(mob.getOrientation);
}

Attributes

Attribute Description Type Default Available Vaules
getIsPc a getter which indicates it is PC or mobile Boolean true true/false
getOrientation a getter which indicates the orientation of the screen in mobile String "" portrait/landscape
onWindowResize function which responsively does detections Funtion - -

License

MIT

Package Sidebar

Install

npm i mob-spy

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

9.23 kB

Total Files

7

Last publish

Collaborators

  • jeren_lu