HTML5 API Detailed (1): Fullscreen full Screen mode

Source: Internet
Author: User

fullscreen API Interface

Property 1:fullscreenelement This property returns the DOM element that is currently in full-screen mode.

Property 2:fullscreenenabled This property returns whether the current document has entered a state that can request full-screen mode.

Method 1:Requestfullscreen () requests into full-screen mode.

Method 2:exitfullscreen () Exits full-screen mode.

Event 1:Fullscreenchange is triggered when entering/exiting full-screen mode switching.

Event 2:Fullscreenerror is triggered when it fails to enter/exit full screen mode.

Because of browser compatibility issues with the fullscreen API, we need to do cross-browser processing when we use it, and refer to the code:

Returns elements that are in full screen across browsers

function Fullscreenelement () {

var Fullscreenele = Document.fullscreenelement | |

document.mozfullscreenelement | |

Document.webkitfullscreenelement;

Note: To get full screen elements after the user authorizes full screen, otherwise fullscreenele is null

Console.log ("Full screen element:" +fullscreenele);

return fullscreenele;

}

Returns whether the current document has entered a state that can request full-screen mode across browsers

function fullscreenenable () {

var isfullscreen = document.fullscreenenabled | |

Window.fullscreen | |

Document.webkitisfullscreen | |

document.msfullscreenenabled;

Note: To get the current status exactly after the user authorizes full screen

if (IsFullScreen) {

Console.log (' Full screen mode ');

}else{

Console.log (' Non-full-screen mode ');

}

}

Launch fullscreen across browsers

function Lanchfullscreen (Element) {

if (Element.requestfullscreen) {

Element.requestfullscreen ();

}

else if (Element.mozrequestfullscreen) {

Element.mozrequestfullscreen ();

}

else if (Element.msrequestfullscreen) {

Element.msrequestfullscreen ();

}

else if (Element.webkitrequestfullscreen) {

Element.webkitrequestfullscreen ();

}

}

Exit fullscreen across browsers

function Exitfullscreen () {

if (Document.exitfullscreen) {

Document.exitfullscreen ();

}

else if (Document.mozcancelfullscreen) {

Document.mozcancelfullscreen ();

}

else if (Document.msexitfullscreen) {

Document.msexifullscreen ();

}

else if (Document.webkitcancelfullscreen) {

Document.webkitcancelfullscreen ();

}

}

Fullscreenchange event handling for each browser

Document.addeventlistener (' Fullscreenchange ', function () {/*code*/});

Document.addeventlistener (' Webkitfullscreenchange ', function () {/*code*/});

Document.addeventlistener (' Mozfullscreenchange ', function () {/*code*/});

Document.addeventlistener (' Msfullscreenchange ', function () {/*code*/});

Fullscreenerror event handling for each browser

Document.addeventlistener (' Fullscreenerror ', function () {/*code*/});

Document.addeventlistener (' Webkitfullscreenerror ', function () {/*code*/});

Document.addeventlistener (' Mozfullscreenerror ', function () {/*code*/);

Document.addeventlistener (' Msfullscreenerror ', function () {/*code*/});

Style code in full-screen mode across browsers

:-webkit-full-screen {}

:-moz-full-screen {}

:-ms-fullscreen {}

: fullscreen {}

HTML5 API Detailed (1): Fullscreen full Screen mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.