Reputation: 1317
I am using $(window).width() and $(window).height()
to get the width and height of the webview, but these always return me the same value and the real width and height of the entire webview.
What I need is to get the width and height of the view port the user currently seeing only so when zooming the width and height of the view port should become smaller.
I need this in order to center a div element within the View port the user seeing only.
Upvotes: 3
Views: 750
Reputation: 820
I'm not really good with javascript but I had this problem Once. I remember it being something to do with targetting inner width. Sometimes you also have to account for the scrollbars depending how you do it.
I found this here: Why is the window.width smaller than the viewport width set in media queries
Similar issues.
function viewport() {
var e = window, a = 'inner';
if (!('innerWidth' in window )) {
a = 'client';
e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
}
var vpWidth = viewport().width;
Upvotes: 1