JavaScript
Fullscreen API
Wrap browser fullscreen operations.
By EZ4Code Team
fullscreenfullscreen
Code
function enterFullscreen(el = document.documentElement) {
return el.requestFullscreen?.() || el.webkitRequestFullscreen?.();
}
function exitFullscreen() {
return document.exitFullscreen?.() || document.webkitExitFullscreen?.();
}
function toggleFullscreen(el) {
document.fullscreenElement ? exitFullscreen() : enterFullscreen(el);
}
document.addEventListener("fullscreenchange", () => {
console.log("fullscreen:", !!document.fullscreenElement);
});Explanation
Wraps the fullscreen API, compatible with webkit prefixes.
More JavaScript Snippets
Array Map Filter Reduce
Chain map, filter, reduce, find, some, and every on arrays.
Array Deduplication
Deduplicate an array using Set.
Deep Clone
Deep clone objects, supporting common data types.
Debounce Function
Wait a period of time after an event triggers before executing; reset the timer if triggered again during the wait.
Throttle Function
Limit a function to execute at most once within a time interval.
Promise.all Concurrency Control
A Promise executor with concurrency limit.