Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi,
i have link and div i want when i click in link i want display my div full screen and i want to make width and height 100%

this is my code please i need help


XML
<html>
<head>
<title>DIV with full screen height</title>
<style>
        #map-canvas
        {
            height: 590px;
            width:1100px;
            border: 2px solid #326195;
            margin: 5px;
            background-color: blue;
        }


        </style>

  <script>
        //foction plein ecran
        var element, fullscreenbtn;
        function intializePlayer() {
            element = document.getElementById('map-canvas');
            fullscreenbtn = document.getElementById('fullscreenbtn');
            // Add event listeners
            fullscreenbtn.addEventListener('click', toggleFullScreen, false);
        }
        window.onload = intializePlayer;

        var fullScreen = false;
        function toggleFullScreen() {
            debugger;
            if (!element.fullscreenElement &&    // alternative standard method
                !element.mozFullScreenElement && !element.webkitFullscreenElement) {  // current working methods
                if (element.requestFullscreen) {
                    element.requestFullscreen();

                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();

                } else if (element.webkitRequestFullscreen) {
                    element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
                }
            } else {
                if (element.cancelFullScreen) {
                    element.cancelFullScreen();
                } else if (element.mozCancelFullScreen) {
                    delementocument.mozCancelFullScreen();
                } else if (document.webkitCancelFullScreen) {
                    element.webkitCancelFullScreen();
                }
            }
        }


    </script>
</style>
</head>
<body>

   <a href="#" id="fullscreenbtn" style="z-index: 10;" >plein ecran</a>


        <div id="map-canvas">

        </div>

</body>
</html>
Posted

First, the idea of "full screen" is wrong. Javascript DOM objects don't "know" is it a full-screen mode or not, and don't need to "know". You need to develop the layout which works well on whatever the inner size of the browser's window is. I hope this is what you really meant to achieve.

Secondly, your question is not really about CSS, but CSS + JavaScript.

First thing you need to understand is: to fill in the full window width is the problem totally different from doing the same for height? Why? Because of the floating nature of HTML rendering: the content is flowing left-to-right or right-to-left first, and only then, when the width is filled, it goes down. So, normally, CSS is more than enough to adjust the layout to the width of the window: you use such properties as width: 100%. You cannot do the same with height: even if CSS had the expressive capabilities to fit in the height, it could contradict the horizontal layout properties. Can you see the point?

So, I would not recommend to fit in both width and height for most pages. At the same time, I can see many cases when doing it would be nice or even required. I do such things myself and think that it can make the whole layout paradigm for in-browser JavaScript programming. One apparent example where such layout is important is the game, but not only.

So, here is the idea for JavaScript approach: you need to adjust your layout through calculations based on two properties:
window.innerHeight and window.innerWidth. It can be a bit more complicated than you would expect, because it can be hard to calculate the actual size of HTML elements.

Anyway, you can find comprehensive example of such layouts in my articles:
JavaScript Calculator,
Tetris on Canvas.

To understand how it works (I hope you already got the idea), you have to read my HTML + CSS and only small part of JavaScript where the properties mentioned above are used. I tried by best to isolate different part of the script and implement layout separately from other code, so learning it would be easy.

—SA
 
Share this answer
 
Comments
Member 11573837 25-May-15 11:00am    
thank you Sergey Alexandrovich Kryukov,
i have solve my self i have add

#map-canvas:-webkit-full-screen { width: 100%; height: 100%; }
#map-canvas:-moz-full-screen { width: 100% ; height: 100%;}
#map-canvas:-ms-full-screen { width: 100% ; height: 100%;}
#map-canvas:-o-full-screen { width: 100% ; height: 100%;}

and it work
Sergey Alexandrovich Kryukov 25-May-15 11:02am    
You are welcome, but will you also accept my answer formally?
—SA
i have add this to my style and it work's

C#
#map-canvas:-webkit-full-screen  { width: 100%; height: 100%; }
        #map-canvas:-moz-full-screen     { width: 100% ; height: 100%;}
        #map-canvas:-ms-full-screen      { width: 100% ; height: 100%;}
        #map-canvas:-o-full-screen       { width: 100% ; height: 100%;}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900