Skip to content

Instantly share code, notes, and snippets.

@coa00
Created June 28, 2018 02:52
Show Gist options
  • Select an option

  • Save coa00/12288b6b586ca4b4915c9d69238af433 to your computer and use it in GitHub Desktop.

Select an option

Save coa00/12288b6b586ca4b4915c9d69238af433 to your computer and use it in GitHub Desktop.
fullscreen を切り替えるライブラリ
export function enableFullScreen() {
const doc = window.document;
return (
doc.fullscreenEnabled ||
doc.webkitFullscreenEnabled ||
doc.mozFullscreenEnabled ||
doc.msFullscreenEnabled
);
}
export function isFullScreen() {
const doc = window.document;
const ret =
doc.fullscreenElement ||
doc.webkitFullscreenElement ||
doc.mozFullscreenElement ||
doc.msFullscreenElement;
return ret;
}
export function toggleFullScreen() {
const doc = window.document;
const docEl = doc.documentElement;
const requestFullScreen =
docEl.requestFullscreen ||
docEl.mozRequestFullScreen ||
docEl.webkitRequestFullScreen ||
docEl.msRequestFullscreen;
const cancelFullScreen =
doc.exitFullscreen ||
doc.mozCancelFullScreen ||
doc.webkitExitFullscreen ||
doc.msExitFullscreen;
if (
!doc.fullscreenElement &&
!doc.mozFullScreenElement &&
!doc.webkitFullscreenElement &&
!doc.msFullscreenElement
) {
requestFullScreen.call(docEl);
} else {
cancelFullScreen.call(doc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment