An open API service indexing awesome lists of open source software.

https://github.com/presentkim/fullscreen-wrapper

Light Wrapper for FullScreen API for cross-browser supports
https://github.com/presentkim/fullscreen-wrapper

Last synced: about 1 year ago
JSON representation

Light Wrapper for FullScreen API for cross-browser supports

Awesome Lists containing this project

README

          

# fullscreen-wrapper
[![npm version](https://img.shields.io/npm/v/fullscreen-wrapper.svg?style=flat-square)](https://www.npmjs.com/package/fullscreen-wrapper)
[![npm license](https://img.shields.io/npm/l/fullscreen-wrapper.svg?style=flat-square)](https://www.npmjs.com/package/fullscreen-wrapper)
[![npm downloads](https://img.shields.io/npm/dt/fullscreen-wrapper.svg?style=flat-square)](https://www.npmjs.com/package/fullscreen-wrapper)
[![bundlee size](https://img.shields.io/bundlephobia/min/fullscreen-wrapper.svg?style=flat-square)](https://bundlephobia.com/package/fullscreen-wrapper)

A Light Wrapper for FullScreen API for cross-browser supports

## Installation

> ```sh
> npm install fullscreen-wrapper --save
> yarn add fullscreen-wrapper
> ```

## Usage

### Import library

> ```javascript
> import fullscreen from 'fullscreen-wrapper';
> //or
> var fullscreen = require('fullscreen-wrapper');
> ```

### Check supported fullscreen features in document

> ```javascript
> //Returns true if document has the ability to display elements fullscreen and fullscreen is supported, or false otherwise.
> if (fullscreen.isEnabled) {
> //do somethings
> }
> ```

### Check supported fullscreen features in document

> ```javascript
> if (fullscreen.isEnabled) {
> //do somethings
> }
> ```

All functions are executed only when fullscreen.isEnabled, so there is no need to check separately.
I think it only needs to be used when adding a fullscreen-button when fullscreen is available.

### Toggle the fullscreen when document clicked

> ```javascript
> //In fact, it works as document.documentElement if no arguments are given.
> document.onclick = () => {
> if (fullscreen.isFullscreen) {
> fullscreen.exit();
> } else {
> fullscreen.request(document.documentElement);
> }
> };
> ```
>
> or use `toggle()` method
>
> ```javascript
> document.onclick = () => fullscreen.toggle(document.documentElement);
> ```

### Listen fullscreen change and error events

> Listen change
>
> ```javascript
> fullscreen.onClick(() => {
> console.log(fullscreen.isFullscreen ? '[Fullscreen] on' : '[Fullscreen] off');
> });
> ```

> Listen error
>
> ```javascript
> fullscreen.onError((err) => console.log(err));
> ```