tags:

views:

24

answers:

1

How can I find the (x,y) point of the center of the viewable area of the browser?

I am using jQuery, if there are any good jQuery helper functions for this.

+2  A: 

Like this:

var x = $(window).width() / 2;
var y = $(window).height() / 2;

If you want the center point of the whole document (not just the viewable area), you can use $(document) instead.

Tatu Ulmanen
i would suggest `.outerWidth(true)` which includes padding / border and margins..
Gaby
@Tatu: Is that the viewport or the entire browser window including the address bar and toolbars and the window borders?
Ricket
@Ricket, no, it's just the width of the content area itself without the 'chrome' of the browser. @Gaby, if I'm not completely mistaken, you cannot set padding / border / margin to `window` so that's irrelevant.
Tatu Ulmanen