mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-02-23 16:42:50 +08:00
Add more readability
This commit is contained in:
parent
bbde995383
commit
479c32b67c
72
README.md
72
README.md
@ -2,73 +2,81 @@
|
||||
|
||||
Cordova plugin to set/lock the screen orientation in a common way for iOS, Android, WP8 and Blackberry 10. This plugin is based on an early version of [Screen Orientation API](http://www.w3.org/TR/screen-orientation/) so the api does not currently match the current spec.
|
||||
|
||||
The plugin adds the following to the screen object:
|
||||
The plugin adds the following to the screen object (`window.screen`):
|
||||
|
||||
__lockOrientation(ORIENTATION_STRING)__
|
||||
lock the device orientation
|
||||
```js
|
||||
// lock the device orientation
|
||||
.lockOrientation('portrait')
|
||||
|
||||
__unlockOrientation()__
|
||||
unlock the orientation
|
||||
// unlock the orientation
|
||||
.unlockOrientation()
|
||||
|
||||
__orientation__
|
||||
current orientation (ORIENTATION_STRING)
|
||||
// current orientation
|
||||
.orientation
|
||||
```
|
||||
|
||||
## Install
|
||||
|
||||
cordova < 4
|
||||
_cordova < 4_
|
||||
|
||||
```bash
|
||||
cordova plugin add net.yoik.cordova.plugins.screenorientation
|
||||
```
|
||||
_cordova > 4_
|
||||
|
||||
cordova > 4
|
||||
|
||||
```bash
|
||||
cordova plugin add cordova-plugin-screen-orientation
|
||||
```
|
||||
|
||||
## Supported Orientations
|
||||
|
||||
__portrait-primary__
|
||||
The orientation is in the primary portrait mode.
|
||||
#### portrait-primary
|
||||
> The orientation is in the primary portrait mode.
|
||||
|
||||
__portrait-secondary__
|
||||
The orientation is in the secondary portrait mode.
|
||||
#### portrait-secondary
|
||||
> The orientation is in the secondary portrait mode.
|
||||
|
||||
__landscape-primary__
|
||||
The orientation is in the primary landscape mode.
|
||||
#### landscape-primary
|
||||
> The orientation is in the primary landscape mode.
|
||||
|
||||
__landscape-secondary__
|
||||
The orientation is in the secondary landscape mode.
|
||||
#### landscape-secondary
|
||||
> The orientation is in the secondary landscape mode.
|
||||
|
||||
__portrait__
|
||||
The orientation is either portrait-primary or portrait-secondary (sensor).
|
||||
#### portrait
|
||||
> The orientation is either portrait-primary or portrait-secondary (sensor).
|
||||
|
||||
__landscape__
|
||||
The orientation is either landscape-primary or landscape-secondary (sensor).
|
||||
#### landscape
|
||||
> The orientation is either landscape-primary or landscape-secondary (sensor).
|
||||
|
||||
## Usage
|
||||
|
||||
// set to either landscape
|
||||
screen.lockOrientation('landscape');
|
||||
```js
|
||||
// set to either landscape
|
||||
screen.lockOrientation('landscape');
|
||||
|
||||
// allow user rotate
|
||||
screen.unlockOrientation();
|
||||
// allow user rotate
|
||||
screen.unlockOrientation();
|
||||
|
||||
// access current orientation
|
||||
console.log('Orientation is ' + screen.orientation);
|
||||
// access current orientation
|
||||
console.log('Orientation is ' + screen.orientation);
|
||||
```
|
||||
|
||||
## Events
|
||||
|
||||
Both android and iOS will fire the orientationchange event on the window object.
|
||||
For this version of the plugin use the window object if you require notification.
|
||||
|
||||
|
||||
For this plugin to follow the full API events should be fired on the screen object.
|
||||
iOS and BB10 do not currently support events on the _screen_ object so custom event
|
||||
handling will need to be added (Suggestions welcome!).
|
||||
|
||||
### Example usage
|
||||
|
||||
window.addEventListener("orientationchange", function(){
|
||||
console.log('Orientation changed to ' + screen.orientation);
|
||||
});
|
||||
```js
|
||||
window.addEventListener("orientationchange", function(){
|
||||
console.log(screen.orientation); // e.g. portrait
|
||||
});
|
||||
```
|
||||
|
||||
## Android Notes
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user