1
所以我有這個JavaScript片有兩個按鈕去全屏和一個退出全屏。我想這樣做,如果我不是全屏按鈕說去全屏幕,當我在全屏幕按鈕說退出全屏幕... 所以基本上,我只需要一個按鈕進入/退出全屏。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>
@adamjcSweet這個作品,但是。只有一次。有一個按鈕是我想要的,它說輸入全屏,當我點擊它時,它進入全屏,並說全屏退出,當我點擊它,退出全屏,並不會回到全屏。不過謝謝...生病了,但是如果你知道一個快速解決方案,請告訴我。 – 2013-05-11 08:13:10
在cancelFullscreen函數中,您需要使用類似的代碼,將按鈕innerHTML更改爲「Enter Full Screen」,並將onclick值分配給enterFullscreen函數。 – adamjc 2013-05-11 08:30:16
我添加了....作品+自定義圖片了。 var screenFull = false; var img = new Image('button')。src =「.//images/up_full.fw.png」; document.getElementById('button')。src =「.//images/up_full.fw.png」; function togle(){ if(screenFull){0} {0} {0} {0} cancelFullscreen(); \t document.getElementById('button')。src =「.//images/up_full.fw.png」; screenFull = false; } else { launchFullscreen(document.documentElement); document.getElementById('button')。src =「.//images/down_full.fw.png」; \t screenFull = true; – 2013-05-11 21:52:51