Skip to content

Latest commit

 

History

History
95 lines (63 loc) · 1.72 KB

readme.md

File metadata and controls

95 lines (63 loc) · 1.72 KB

Get the current screen orientation

Install

$ npm install --save screen-orientation-2

or

$ npm add screen-orientation-2

Usage

Import module

const screenOrientation = require('screen-orientation-2')
screenOrientation()
//=> {direction: 'landscape', version: 'primary', angle: 0}

Or

screenOrientation.getScreenOrientation()
//=> {direction: 'landscape', version: 'primary', angle: 0}
screenOrientation.addEventOnOrientationChange((newOrientation) => {
  console.log(newOrientation)
  //=> {direction: 'landscape', version: 'primary', angle: 0}
})
screenOrientation.removeEventOnOrientationChange()
//=> void
screenOrientation.setUseOrientation()
//=> void
screenOrientation.setUseWindowSize()
//=> void

API

screenOrientation() -> object

Returns the current screen orientation (direction, version and angle).

screenOrientation.getScreenOrientation() -> object

Returns the current screen orientation (direction, version and angle).

screenOrientation.addEventOnOrientationChange(callback) -> void

Add a callback function when screen orientation is changed

Example:

const refreshFrames(newOrientation) {
  // myFunction (newOrientation.direction, newOrientation.version)
};

screenOrientation.addEventOnOrientationChange(refreshFrames)

screenOrientation.removeEventOnOrientationChange() -> void

Remove a callback function when screen orientation is changed

screenOrientation.setUseOrientation() -> void

Force use window.screen.orientation object

screenOrientation.setUseWindowSize() -> void

Force use window size

License

MIT © Medeiros Dev