crmpicco
crmpicco

Reputation: 17181

jQuery get the document width and height excluding horizontal/vertical scrollbars

I have a piece of jQuery on my site that displays an overlay the full width and height of the window. I have an issue in that if the overlay is closed (as there is an option to close it) I lose the vertical scroll bar from my window. Is there a way to specify the width and height excluding any horizontal or vertical scrollbars?

This is my code below, the jQuery will run as soon as the page loads.

    <div id="screen"></div>

        $('#screen').css({ "display": "block", 
                            opacity  : 0.7,
                            "width"  : $(document).width(),
                            "height" : $(document).height()
                            });
        $('body').css({ "overflow" : "hidden" });

Upvotes: 0

Views: 589

Answers (1)

crmpicco
crmpicco

Reputation: 17181

This works:

$('#screen').css({ "display": "block", 
                    opacity  : 0.7,
                    "width"  : $(document).width(),
                    "height" : $(document).height()
                    });
$('body').css({ "overflow" : "auto" });

Upvotes: 1

Related Questions