How can I center a div in jQuery independent of scrolling height?
I'm using the following snippet to center a popup. It works well if you have not scrolled down.

If I try to load the popup after scrolling down, say from a link at the bottom of the page, the popup appears at the top. Unless I scroll up, I wont be able to see it.

How can I change the behavior so that the popup appears at the center of the screen regardless of scrolling height?

    var winH = $(window).height(),
        winW = $(window).width();
    $(".popup").css('top', winH / 2 - $(".popup").height() / 2);
    $(".popup").css('left', winW / 2 - $(".popup").width() / 2);

CSS:

    .popup {
    	overflow:hidden;
    	position:absolute;
    	width:600px;
    	z-index:1000;
    }



How can I center a div in jQuery independent of scrolling height?
===

I'm using the following snippet to center a popup. It works well if you have not scrolled down.

If I try to load the popup after scrolling down, say from a link at the bottom of the page, the popup appears at the top. Unless I scroll up, I wont be able to see it.

How can I change the behavior so that the popup appears at the center of the screen regardless of scrolling height?

    var winH = $(window).height(),
        winW = $(window).width();
    $(".popup").css('top', winH / 2 - $(".popup").height() / 2);
    $(".popup").css('left', winW / 2 - $(".popup").width() / 2);

CSS:

    .popup {
    	overflow:hidden;
    	position:absolute;
    	width:600px;
    	z-index:1000;
    }


