所以我有这个javascript片段,它有两个按钮可以进入全屏,一个按钮可以退出全屏。我想这样做,如果我不是全屏,按钮说进入全屏,当我全屏时,按钮说退出全屏......所以基本上我只需要一个按钮就可以进入/退出全屏屏幕。
<html>
<head>
<script>
function launchFullscreen(element) {
if(element.requestFullScreen) {
element.requestFullScreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
function cancelFullscreen() {
if(document.cancelFullScreen) {
document.cancelFullScreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
</script>
</head>
<body>
<button onclick="launchFullscreen(document.documentElement);">Launch Fullscreen</button>
<button onclick="cancelFullscreen();">Hide Fullscreen</button>
</body>
</html>