Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize full screen of HTML5 video player

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to achieve full-screen HTML5 video player". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First of all, the title is misleading, but the reason for changing the title in this way is mainly because video uses more

In html5, the full-screen method can be applied to many html elements, not just video

The code is as follows:

Full screen issu

* {

Padding: 0px

Margin: 0px

}

Body div.videobox {

Width: 400px

Height: 320px

Margin: 100px auto

Background-color:#000

}

Body div.videobox video.video

{

Width: 100%

Height: 100%

}

:-webkit-full-screen {

}

:-moz-full-screen {

}

:-ms-fullscreen {

}

:-o-fullscreen {

}

: full-screen {

}

: fullscreen {

}

:-webkit-full-screen video {

Width: 100%

Height: 100%

}

:-moz-full-screen video {

Width: 100%

Height: 100%

}

Full screen

/ / reflection usage

Var invokeFieldOrMethod = function (element, method)

{

Var usablePrefixMethod

["webkit", "moz", "ms", "o", ""] .forEach (function (prefix) {

If (usablePrefixMethod) return

If (prefix = "") {

/ / No prefix, method initials are lowercase

Method = method.slice (0jue 1). ToLowerCase () + method.slice (1)

}

Var typePrefixMethod = typeof element [prefix + method]

If (typePrefixMethod + ""! = = "undefined") {

If (typePrefixMethod = = "function") {

UsablePrefixMethod = element [prefix + method] ()

} else {

UsablePrefixMethod = element [prefix + method]

}

}

});

Return usablePrefixMethod

}

/ / enter full screen

Function launchFullscreen (element)

{

/ / this method cannot be run in the step task, otherwise Firefox will not be able to full screen

If (element.requestFullscreen) {

Element.requestFullscreen ()

} else if (element.mozRequestFullScreen) {

Element.mozRequestFullScreen ()

} else if (element.msRequestFullscreen) {

Element.msRequestFullscreen ()

} else if (element.oRequestFullscreen) {

Element.oRequestFullscreen ()

}

Else if (element.webkitRequestFullscreen)

{

Element.webkitRequestFullScreen ()

} else {

Var docHtml = document.documentElement

Var docBody = document.body

Var videobox = document.getElementById ('videobox')

Var cssText = 'width:100%;height:100%;overflow:hidden;'

DocHtml.style.cssText = cssText

DocBody.style.cssText = cssText

Videobox.style.cssText = cssText+';'+'margin:0px;padding:0px;'

Document.IsFullScreen = true

}

}

/ / exit full screen

Function exitFullscreen ()

{

If (document.exitFullscreen) {

Document.exitFullscreen ()

} else if (document.msExitFullscreen) {

Document.msExitFullscreen ()

} else if (document.mozCancelFullScreen) {

Document.mozCancelFullScreen ()

} else if (document.oRequestFullscreen) {

Document.oCancelFullScreen ()

} else if (document.webkitExitFullscreen) {

Document.webkitExitFullscreen ()

} else {

Var docHtml = document.documentElement

Var docBody = document.body

Var videobox = document.getElementById ('videobox')

DocHtml.style.cssText = ""

DocBody.style.cssText = ""

Videobox.style.cssText = ""

Document.IsFullScreen = false

}

}

Document.getElementById ('fullScreenBtn'). AddEventListener (' click',function () {

LaunchFullscreen (document.getElementById ('video'))

Window.setTimeout (function exit () {

/ / check whether the processor is on full screen.

If (invokeFieldOrMethod (document,'FullScreen') | | invokeFieldOrMethod (document,'IsFullScreen') | | document.IsFullScreen)

{

ExitFullscreen ()

}

}, 5: 1000)

}, false)

This is the end of the content of "how to achieve full screen of HTML5 video player". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report