toggle-fullscreen
Promise based Fullscreen API for cross-browser.
{ const element = document; await ; await ;}
Install
npm install --save toggle-fullscreen
API
Promise<>
toggleFullscreen(target) ⇒ Requests Fullscreen API. Request to exit fullscreen mode if target is already fullscreen.
Param | Type | Description |
---|---|---|
target | Element |
target element to change fullscreen |
Usage:
var target = document;;
For jQuery:
;
Promise<>
fullscreenChange(callback) ⇒ Add a listener for when the browser switches in and out of fullscreen.
Param | Type | Description |
---|---|---|
callback | function |
function to be called when the browser switches in and out of fullscreen |
Usage:
;
Boolean
isFullscreen() ⇒ Check whether fullscreen is active. Usage:
if console; else console;
Example
import toggleFullscreen fullscreenChange isFullscreen from 'toggle-fullscreen'; { const element = document; ;};
Or use Promise.all()
import toggleFullscreen fullscreenChange isFullscreen from 'toggle-fullscreen'; { // target element const element = document; // callback function when fullscreen change is detected. const callback = const isFullScreen = ; this; if isFullScreen document; elementstylewidth = '70%'; else document; elementstylewidth = '100%'; ; // execute toggle-fullscreen and add listener when fullscreen change detected asynchronously Promise;};
For async/await:
import toggleFullscreen fullscreenChange isFullscreen from 'toggle-fullscreen'; onChangeFullScreen = const element = document; await ; await ; console;;
For callback (use if something is wrong with Promise) :
const toggleFullscreen = ; { const element = document; ;};
Support
- Chrome@latest
- Firefox@latest
- Safari@latest
- MSEdge@latest
- IE11
License
This project is licensed under the terms of the MIT license