fullscreen-wrapper
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

fullscreen-wrapper

npm version npm license npm downloads bundlee size

A Light Wrapper for FullScreen API for cross-browser supports

Installation

npm install fullscreen-wrapper --save
yarn add fullscreen-wrapper

Usage

Import library

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

Check supported fullscreen features in document

//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

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

//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

document.onclick = () => fullscreen.toggle(document.documentElement);

Listen fullscreen change and error events

Listen change

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

Listen error

fullscreen.onError((err) => console.log(err));

Package Sidebar

Install

npm i fullscreen-wrapper

Weekly Downloads

1

Version

1.1.3

License

MIT

Unpacked Size

6.92 kB

Total Files

4

Last publish

Collaborators

  • presentkim