验证中...
Languages: JavaScript
Categories: JavaScript 工具
Latest update 2019-05-31 23:26
JS全屏代码
Raw Copy
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button onclick="toggleFullScreen(event)">点我全屏</button>
<script>
function FullScreen(el) {
var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
if (!isFullscreen) { //进入全屏,多重短路表达式
(el.requestFullscreen && el.requestFullscreen()) ||
(el.mozRequestFullScreen && el.mozRequestFullScreen()) ||
(el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen());
} else { //退出全屏,三目运算符
document.exitFullscreen ? document.exitFullscreen() :
document.mozCancelFullScreen ? document.mozCancelFullScreen() :
document.webkitExitFullscreen ? document.webkitExitFullscreen() : '';
}
}
function toggleFullScreen(e) {
var el = e.srcElement || e.target; //target兼容Firefox
el.innerHTML == '点我全屏' ? el.innerHTML = '退出全屏' : el.innerHTML = '点我全屏';
FullScreen(el);
}
</script>
</body>
</html>

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close