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其實還沒有正規(guī)實現(xiàn), 得加webkit前綴.