screenfull.js alternatives and similar libraries
Based on the "Modals and Popups" category.
Alternatively, view screenfull alternatives based on common mentions on social networks and blogs.
-
sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. -
Magnific-Popup
Light and responsive lightbox script with focus on performance. -
fancyBox
jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable. -
X-editable
In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery -
tether
A positioning engine to make overlays, tooltips and dropdowns better -
vex
A modern dialog library which is highly configurable and easy to style. #hubspot-open-source -
lightGallery
A customizable, modular, responsive, lightbox gallery plugin. -
bootstrap-modal
Extends the default Bootstrap Modal class. Responsive, stackable, ajax and more. -
Bootbox
Wrappers for JavaScript alert(), confirm() and other flexible dialogs using Twitter's bootstrap framework -
colorbox
A light-weight, customizable lightbox plugin for jQuery -
lightgallery.js
Full featured JavaScript image & video gallery. No dependencies -
baguetteBox.js
:zap: Simple and easy to use lightbox script written in pure JavaScript -
iziModal
Elegant, responsive, flexible and lightweight modal plugin with jQuery. -
jquery.avgrund.js
Avgrund is jQuery plugin with new modal concept for popups -
css-modal
A modal built with pure CSS, enhanced with JavaScript -
jBox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more. -
GLightbox
Pure Javascript lightbox with mobile support. It can handle images, videos with autoplay, inline content and iframes -
🦞 Modali
A delightful modal dialog component for React, built from the ground up to support React Hooks. -
hColumns
jQuery.hColumns is a jQuery plugin that looks like Mac OS X Finder's column view for the hierarchical data. -
F$D€
F$D€ - Client not paid? Add opacity to the body tag and increase it every day until their site completely fades away -
ModalSquared.js
ModalSquared.js is a super small less than a 1kb library for showing and hiding modals.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of screenfull.js or a related project?
README
screenfull
Simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which lets you bring the page or any element into fullscreen. Smoothens out the browser implementation differences, so you don't have to.
This package is ESM. Please familiarize yourself with what that implies.\ If you cannot use ESM or need to support older browsers without using transpilation, use version 5.2.0.
This package is feature complete. No new features will be accepted.
Demo
Install
Only 0.7 kB gzipped.
npm install screenfull
Also available on cdnjs (older version).
Why?
Screenfull
import screenfull from 'screenfull';
if (screenfull.isEnabled) {
screenfull.request();
}
Vanilla JavaScript
document.fullscreenEnabled =
document.fullscreenEnabled ||
document.mozFullScreenEnabled ||
document.documentElement.webkitRequestFullScreen;
function requestFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
}
if (document.fullscreenEnabled) {
requestFullscreen(document.documentElement);
}
// This is not even entirely comprehensive. There's more.
Support
Note: Safari is supported on desktop and iPad, but not on iPhone. This is a limitation in the browser, not in Screenfull.
Documentation
Examples
Fullscreen the page
import screenfull from 'screenfull';
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request();
} else {
// Ignore or do something else
}
});
Fullscreen an element
import screenfull from 'screenfull';
const element = document.getElementById('target');
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element);
}
});
Hide navigation user-interface on mobile devices
import screenfull from 'screenfull';
const element = document.getElementById('target');
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element, {navigationUI: 'hide'});
}
});
Fullscreen an element with jQuery
import screenfull from 'screenfull';
const element = $('#target')[0]; // Get DOM element from jQuery collection
$('#button').on('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element);
}
});
Toggle fullscreen on a image with jQuery
import screenfull from 'screenfull';
$('img').on('click', event => {
if (screenfull.isEnabled) {
screenfull.toggle(event.target);
}
});
Detect fullscreen change
import screenfull from 'screenfull';
if (screenfull.isEnabled) {
screenfull.on('change', () => {
console.log('Am I fullscreen?', screenfull.isFullscreen ? 'Yes' : 'No');
});
}
Remove listeners with:
import screenfull from 'screenfull';
screenfull.off('change', callback);
Detect fullscreen error
import screenfull from 'screenfull';
if (screenfull.isEnabled) {
screenfull.on('error', event => {
console.error('Failed to enable fullscreen', event);
});
}
See the demo for more examples, and view the source.
Fullscreen an element with Angular.js
You can use the Angular.js binding to do something like:
<div ngsf-fullscreen>
<p>This is a fullscreen element</p>
<button ngsf-toggle-fullscreen>Toggle fullscreen</button>
</div>
Fullscreen the page with Angular 2
import {Directive, HostListener} from '@angular/core';
import screenfull from 'screenfull';
@Directive({
selector: '[toggleFullscreen]'
})
export class ToggleFullscreenDirective {
@HostListener('click') onClick() {
if (screenfull.isEnabled) {
screenfull.toggle();
}
}
}
<button toggleFullscreen>Toggle fullscreen<button>
API
.request(element, options?)
Make an element fullscreen.
Accepts a DOM element and FullscreenOptions
.
The default element is <html>
. If called with another element than the currently active, it will switch to that if it's a descendant.
If your page is inside an <iframe>
you will need to add a allowfullscreen
attribute (+ webkitallowfullscreen
and mozallowfullscreen
).
Keep in mind that the browser will only enter fullscreen when initiated by user events like click, touch, key.
Returns a promise that resolves after the element enters fullscreen.
.exit()
Brings you out of fullscreen.
Returns a promise that resolves after the element exits fullscreen.
.toggle(element, options?)
Requests fullscreen if not active, otherwise exits.
Accepts a DOM element and FullscreenOptions
.
Returns a promise that resolves after the element enters/exits fullscreen.
.on(event, function)
Events: 'change' | 'error'
Add a listener for when the browser switches in and out of fullscreen or when there is an error.
.off(event, function)
Remove a previously registered event listener.
.onchange(function)
Alias for .on('change', function)
.onerror(function)
Alias for .on('error', function)
.isFullscreen
Returns a boolean whether fullscreen is active.
.element
Returns the element currently in fullscreen, otherwise undefined
.
.isEnabled
Returns a boolean whether you are allowed to enter fullscreen. If your page is inside an <iframe>
you will need to add a allowfullscreen
attribute (+ webkitallowfullscreen
and mozallowfullscreen
).
.raw
Exposes the raw properties (prefixed if needed) used internally: requestFullscreen
, exitFullscreen
, fullscreenElement
, fullscreenEnabled
, fullscreenchange
, fullscreenerror
FAQ
How can I navigate to a new page when fullscreen?
That's not supported by browsers for security reasons. There is, however, a dirty workaround. Create a seamless iframe that fills the screen and navigate to the page in that instead.
import screenfull from 'screenfull';
document.querySelector('#new-page-button').addEventListener(() => {
const iframe = document.createElement('iframe')
iframe.setAttribute('id', 'external-iframe');
iframe.setAttribute('src', 'https://new-page-website.com');
iframe.setAttribute('frameborder', 'no');
iframe.style.position = 'absolute';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.style.bottom = '0';
iframe.style.left = '0';
iframe.style.width = '100%';
iframe.style.height = '100%';
document.body.prepend(iframe);
document.body.style.overflow = 'hidden';
});