DEV Community

Israel Rotimi
Israel Rotimi

Posted on

Dev challenge: The Fullscreen API

This is a submission for DEV Challenge v24.03.20, One Byte Explainer: Browser API or Feature.

The Fullscreen API:

The Fullscreen API

The fullscreen API is used to toggle fullscreen on webpages. This can be useful in games and videos where we may want to toggle fullscreen to phase out distractions for an imersive experience. It has no interface, but adds methods to the Document and Elementinterfaces.

How to use:

  • use Element.requestFullscreen()to place the element in fullscreen mode

  • use document.exitFullscreen()to exit fullscreen

Basic example:

const canvas = document.getElementById('canvas');
canvas.addEventListener(
  "keydown",
  (e) => {
    if (e.key === "Enter") {
      toggleFullScreen();
    }
  },
);
function toggleFullscreen(){
  if(!document.fullscreenElement){
    canvas.requestFullscreen();
  }else {
    document.exitFullscreen();
  }
}
Enter fullscreen mode Exit fullscreen mode

source: MDN web docs

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more