toggleFullscreen() {
const elem = document.querySelector('xxxx'); // 得到你想要全屏的DOM元素
if (document.webkitCurrentFullScreenElement || document.mozFullScreenElement) {
document.webkitExitFullscreen ? document.webkitExitFullscreen() : '';
document.mozCancelFullScreen ? document.mozCancelFullScreen() : '';
} else {
elem.mozRequestFullScreen ? elem.mozRequestFullScreen() : '';
elem.webkitRequestFullScreen ? elem.webkitRequestFullScreen() : '';
}
},
在chrome
和firefox
下测试通过. chrome 56下, w3c的api其实还没有正规实现, 得加webkit前缀.