fullscreenchange
event is fired immediately after an
元素
switches into or out of full-screen mode.
| 冒泡 | Yes |
|---|---|
| 可取消 | No |
| 接口 |
事件
|
| 事件处理程序特性 |
onfullscreenchange
|
This event is sent to the
元素
which is transitioning into or out of full-screen mode.
In this example, a handler for the
fullscreenchange
event is added to the element whose ID is
fullscreen-div
.
If the user clicks on the "Toggle Fullscreen Mode" button, the
click
handler will toggle full-screen mode for the
div
。若
document.fullscreenElement
has a value it will exit full-screen mode. If not, the div will be placed into full-screen mode.
Remember that by the time the
fullscreenchange
event is handled, the status of the element has already changed. So if the change is to full-screen mode,
document.fullscreenElement
will point to the element that is now in full-screen mode. On the other hand, if
document.fullscreenElement
is null, full-screen mode has been canceled.
What that means to the example code is that, if an element is currently in full-screen mode, the
fullscreenchange
handler logs the
id
of the full-screen element to the console. If
document.fullscreenElement
is null, the code logs a message that the change is to leave full-screen mode.
<h1>fullscreenchange event example</h1> <div id="fullscreen-div"> <button id="toggle-fullscreen">Toggle Fullscreen Mode</button> </div>
document.getElementById('fullscreen-div').addEventListener('fullscreenchange', (event) => {
// document.fullscreenElement will point to the element that
// is in fullscreen mode if there is one. If not, the value
// of the property is null.
if (document.fullscreenElement) {
console.log(`Element: ${document.fullscreenElement.id} entered fullscreen mode.`);
} else {
console.log('Leaving full-screen mode.');
}
});
document.getElementById('toggle-fullscreen').addEventListener('click', (event) => {
if (document.fullscreenElement) {
// exitFullscreen is only available on the Document object.
document.exitFullscreen();
} else {
document.getElementById('fullscreen-div').requestFullscreen();
}
});
| 规范 | 状态 |
|---|---|
| 全屏 API | 实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
fullscreenchange
event
|
Chrome 57 | Edge ≤79 |
Firefox
64
|
IE ? | Opera 44 | Safari ? | WebView Android 57 | Chrome Android 57 |
Firefox Android
64
|
Opera Android 43 | Safari iOS ? | Samsung Internet Android 7.0 |
完整支持
兼容性未知
使用非标名称。
元素
accessKey
属性
childElementCount
children
classList
className
clientHeight
clientLeft
clientTop
clientWidth
currentStyle
firstElementChild
id
innerHTML
lastElementChild
localName
名称
namespaceURI
nextElementSibling
onfullscreenchange
onfullscreenerror
openOrClosedShadowRoot
outerHTML
part
prefix
previousElementSibling
runtimeStyle
scrollHeight
scrollLeft
scrollLeftMax
scrollTop
scrollTopMax
scrollWidth
shadowRoot
slot
tabStop
tagName
after()
animate()
append()
attachShadow()
before()
closest()
computedStyleMap()
createShadowRoot()
getAnimations()
getAttribute()
getAttributeNames()
getAttributeNode()
getAttributeNodeNS()
getAttributeNS()
getBoundingClientRect()
getClientRects()
getElementsByClassName()
getElementsByTagName()
getElementsByTagNameNS()
hasAttribute()
hasAttributeNS()
hasAttributes()
hasPointerCapture()
insertAdjacentElement()
insertAdjacentHTML()
insertAdjacentText()
matches()
msZoomTo()
prepend()
querySelector()
querySelector()
querySelectorAll()
querySelectorAll()
releasePointerCapture()
remove()
removeAttribute()
removeAttributeNode()
removeAttributeNS()
replaceChildren()
replaceWith()
requestFullscreen()
requestPointerLock()
scroll()
scrollBy()
scrollIntoView()
scrollIntoViewIfNeeded()
scrollTo()
setAttribute()
setAttributeNode()
setAttributeNodeNS()
setAttributeNS()
setCapture()
setPointerCapture()
toggleAttribute()
afterscriptexecute
auxclick
blur
click
compositionend
compositionstart
compositionupdate
contextmenu
copy
cut
dblclick
DOMActivate
DOMMouseScroll
error
focus
focusin
focusout
fullscreenchange
fullscreenerror
gesturechange
gestureend
gesturestart
keydown
keypress
keyup
mousedown
mouseenter
mouseleave
mousemove
mouseout
mouseover
mouseup
mousewheel
MozMousePixelScroll
msContentZoom
MSGestureChange
MSGestureEnd
MSGestureHold
MSGestureStart
MSGestureTap
MSInertiaStart
MSManipulationStateChanged
overflow
paste
scroll
select
show
touchcancel
touchend
touchmove
touchstart
underflow
webkitmouseforcechanged
webkitmouseforcedown
webkitmouseforceup
webkitmouseforcewillbegin
wheel