我不知道如何修改以下代码以包含切换按钮。在“正常”模式下,该按钮将使元素全屏显示,然后更改其功能以返回“正常”状态。
我修改了John Dyer 的 Native Fullscreen JavaScript API示例中的代码:
var fsButton = document.getElementById('fsbutton'),
fsElement = document.getElementById('specialstuff'),
fsStatus = document.getElementById('fsstatus');
if (window.fullScreenApi.supportsFullScreen) {
fsStatus.innerHTML = 'YES: Your browser supports FullScreen';
fsStatus.className = 'fullScreenSupported';
// handle button click
fsButton.addEventListener('click', function() {
window.fullScreenApi.requestFullScreen(fsElement);
}, true);
fsElement.addEventListener(fullScreenApi.fullScreenEventName, function() {
if (fullScreenApi.isFullScreen()) {
fsStatus.innerHTML = 'Whoa, you went fullscreen';
} else {
fsStatus.innerHTML = 'Back to normal';
}
}, true);
} else {
fsStatus.innerHTML = 'SORRY: Your browser does not support FullScreen';
}
对此:
var container = document.getElementById('canvas'),
fsButton = document.getElementById('fsbutton');
if (window.fullScreenApi.supportsFullScreen) { // fullscreen supported
fsButton.style.display = 'block';
container.addEventListener(fullScreenApi.fullScreenEventName, function() {
fsButton.addEventListener('click', function() {
if (fullScreenApi.isFullScreen()) { // fullscreen is on
window.fullScreenApi.CancelFullScreen( container );
fsButton.className = 'fs-off';
} else { // fullscreen is off
window.fullScreenApi.requestFullScreen( container );
container.style.width = "100%";
container.style.height = "100%";
fsButton.className = 'fs-on';
}
}, true)
}, true);
} else {
// no fullscreen support - do nothing
}
但它不起作用。任何建议都非常感谢!