Get the current screen orientation
$ npm install --save screen-orientation-2
or
$ npm add screen-orientation-2
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
Returns the current screen orientation (direction, version and angle).
Returns the current screen orientation (direction, version and angle).
Add a callback function when screen orientation is changed
Example:
const refreshFrames(newOrientation) {
// myFunction (newOrientation.direction, newOrientation.version)
};
screenOrientation.addEventOnOrientationChange(refreshFrames)
Remove a callback function when screen orientation is changed
Force use window.screen.orientation object
Force use window size
MIT © Medeiros Dev