fullscreen

JavaScript, Browser

Opens or closes an element in fullscreen mode.

  • Use Document.querySelector() and Element.requestFullscreen() to open the given element in fullscreen.
  • Use Document.exitFullscreen() to exit fullscreen mode.
  • Omit the second argument, el, to use body as the default element.
  • Omit the first element, mode, to open the element in fullscreen mode by default.
const fullscreen = (mode = true, el = 'body') =>
  mode
    ? document.querySelector(el).requestFullscreen()
    : document.exitFullscreen();
fullscreen(); // Opens `body` in fullscreen mode
fullscreen(false); // Exits fullscreen mode

Recommended snippets

  • renderElement

    JavaScript, Browser

    Renders the given DOM tree in the specified DOM element.

  • serializeForm

    JavaScript, Browser

    Encodes a set of form elements as a query string.

  • addMultipleListeners

    JavaScript, Browser

    Adds multiple event listeners with the same handler to an element.