mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-02-24 00:52:50 +08:00
commit
d89dc2ab41
56
README.md
56
README.md
@ -2,49 +2,55 @@
|
|||||||
|
|
||||||
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.
|
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)__
|
```js
|
||||||
lock the device orientation
|
// lock the device orientation
|
||||||
|
.lockOrientation('portrait')
|
||||||
|
|
||||||
__unlockOrientation()__
|
// unlock the orientation
|
||||||
unlock the orientation
|
.unlockOrientation()
|
||||||
|
|
||||||
__orientation__
|
// current orientation
|
||||||
current orientation (ORIENTATION_STRING)
|
.orientation
|
||||||
|
```
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
cordova < 4
|
_cordova < 4_
|
||||||
|
|
||||||
|
```bash
|
||||||
cordova plugin add net.yoik.cordova.plugins.screenorientation
|
cordova plugin add net.yoik.cordova.plugins.screenorientation
|
||||||
|
```
|
||||||
|
_cordova > 4_
|
||||||
|
|
||||||
cordova > 4
|
```bash
|
||||||
|
|
||||||
cordova plugin add cordova-plugin-screen-orientation
|
cordova plugin add cordova-plugin-screen-orientation
|
||||||
|
```
|
||||||
|
|
||||||
## Supported Orientations
|
## Supported Orientations
|
||||||
|
|
||||||
__portrait-primary__
|
#### portrait-primary
|
||||||
The orientation is in the primary portrait mode.
|
> The orientation is in the primary portrait mode.
|
||||||
|
|
||||||
__portrait-secondary__
|
#### portrait-secondary
|
||||||
The orientation is in the secondary portrait mode.
|
> The orientation is in the secondary portrait mode.
|
||||||
|
|
||||||
__landscape-primary__
|
#### landscape-primary
|
||||||
The orientation is in the primary landscape mode.
|
> The orientation is in the primary landscape mode.
|
||||||
|
|
||||||
__landscape-secondary__
|
#### landscape-secondary
|
||||||
The orientation is in the secondary landscape mode.
|
> The orientation is in the secondary landscape mode.
|
||||||
|
|
||||||
__portrait__
|
#### portrait
|
||||||
The orientation is either portrait-primary or portrait-secondary (sensor).
|
> The orientation is either portrait-primary or portrait-secondary (sensor).
|
||||||
|
|
||||||
__landscape__
|
#### landscape
|
||||||
The orientation is either landscape-primary or landscape-secondary (sensor).
|
> The orientation is either landscape-primary or landscape-secondary (sensor).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
// set to either landscape
|
// set to either landscape
|
||||||
screen.lockOrientation('landscape');
|
screen.lockOrientation('landscape');
|
||||||
|
|
||||||
@ -53,22 +59,24 @@ The orientation is either landscape-primary or landscape-secondary (sensor).
|
|||||||
|
|
||||||
// access current orientation
|
// access current orientation
|
||||||
console.log('Orientation is ' + screen.orientation);
|
console.log('Orientation is ' + screen.orientation);
|
||||||
|
```
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
|
||||||
Both android and iOS will fire the orientationchange event on the window object.
|
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 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.
|
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
|
iOS and BB10 do not currently support events on the _screen_ object so custom event
|
||||||
handling will need to be added (Suggestions welcome!).
|
handling will need to be added (Suggestions welcome!).
|
||||||
|
|
||||||
### Example usage
|
### Example usage
|
||||||
|
|
||||||
|
```js
|
||||||
window.addEventListener("orientationchange", function(){
|
window.addEventListener("orientationchange", function(){
|
||||||
console.log('Orientation changed to ' + screen.orientation);
|
console.log(screen.orientation); // e.g. portrait
|
||||||
});
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Android Notes
|
## Android Notes
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user