I have a div that I want to go full-screen (100% width/height of Window size) onClick of a seperate button, image or link. How would I go about this using Javascript/jQuery?
You'll want a fixed position element at 100% width and height , if you don't have a background color or image you'll be able to click through it. Set z-index higher then all other elements to ensure it is at the front if you need that.
Try pressing F11 versus pressing the button in the example to enter the fullscreen mode. Using F11 the entire page will be fullscreen mode, not just the element itself. The element's styles won't change.
Firstly, you will want to drag a Container Element onto your page. From the right-hand menu of the editor, you will notice that there is a "Full Width" toggle. Toggling this will set this Container Element to full width on your page.
Other solutions describe hiding browser chrome with the HTML5 fullscreen API, well supported as of Oct'20.
This jQuery will expand an element to the viewport :
$('#theButton').click(function() {
$('#theDiv').css({
position: 'fixed',
top: 0,
right: 0,
bottom: 0,
left: 0,
zIndex: 999
});
});
You can use the Following function to make any div Full Screen
function goFullScreen(){
var elem = document.getElementById(temp);
if(elem.requestFullscreen){
elem.requestFullscreen();
}
else if(elem.mozRequestFullScreen){
elem.mozRequestFullScreen();
}
else if(elem.webkitRequestFullscreen){
elem.webkitRequestFullscreen();
}
else if(elem.msRequestFullscreen){
elem.msRequestFullscreen();
}
}
And to exit the Full Screen you can use the following function
function exitFullScreen(){
if(document.exitFullscreen){
document.exitFullscreen();
}
else if(document.mozCancelFullScreen){
document.mozCancelFullScreen();
}
else if(document.webkitExitFullscreen){
document.webkitExitFullscreen();
}
else if(document.msExitFullscreen){
document.msExitFullscreen();
}
}
The code works on any browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With