Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Click/tap fullscreen html5 video to exit fullscreen

Goal

  • I have a video setup that plays fullscreen when a link on the page is tapped on a mobile device. This works fine.
  • I have hidden the HTML5 video controls via CSS - I want the video to be completely clean without any controls.
  • I want to be able to close the fullscreen video by tapping again the fullscreen video itself.
  • I also need to be able to add a class to the body and pause the video on close. The reason for adding the class is that I want to show and hide the video itself, so adding the class lets me control the css for the whole page as a state change.

Problem

When I hit esc for example, or Back on an Android mobile it obviously won't run the function.

How can I detect when fullscreen has been exited to run whatever functions I want?

Code

videoSmallTrigger.on('click', function() {

    // Activate
    if (!document.isFullScreen && !document.fullscreenElement && !document.webkitFullscreenElement && !document.mozFullScreenElement && !document.msFullscreenElement) {

        console.log('trigger open');
        launchFullscreen(videoSmallID);
        body.addClass('fullscreen-video-sm');
        videoSmall.get(0).play();

    }
    // Deactivate
    else {

        console.log('trigger close');
        exitFullscreen();
        body.removeClass('fullscreen-video-sm');
        videoSmall.get(0).pause();

    }

});

function launchFullscreen(element) {
   
    if (element.requestFullscreen) {
        element.requestFullscreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
    } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    }

}

function exitFullscreen() {

  if(document.exitFullscreen) {
    document.exitFullscreen();
  } else if(document.mozCancelFullScreen) {
    document.mozCancelFullScreen();
  } else if(document.webkitExitFullscreen) {
    document.webkitExitFullscreen();
  }

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solved it using a combination of this post and some of the comments beneath it:

How to detect when a page exits fullscreen?

if (document.addEventListener) {
    document.addEventListener('fullscreenchange', exitHandler, false);
    document.addEventListener('mozfullscreenchange', exitHandler, false);
    document.addEventListener('MSFullscreenChange', exitHandler, false);
    document.addEventListener('webkitfullscreenchange', exitHandler, false);
}

function exitHandler() {
    if (!document.isFullScreen && !document.webkitIsFullScreen && !document.mozFullScreen && !document.msFullscreenElement) {

        // Code to run when you exit fullscreen by hitting the ESC key etc.

        body.removeClass('fullscreen-video-sm');
        videoSmall.get(0).pause();
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!