Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make div 'fullscreen' onClick of a button?

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?

like image 696
Dean Avatar asked Mar 08 '12 15:03

Dean


People also ask

How do I make Div full screen on button click?

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.

How do I make CSS full screen?

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.

How do you make a full page container?

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.


2 Answers

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
    });
});
like image 144
Joseph Silber Avatar answered Sep 17 '22 10:09

Joseph Silber


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.

like image 40
Ajinkya Bodade Avatar answered Sep 18 '22 10:09

Ajinkya Bodade