I have a jquery popup script, and to center the popup on the screen the code is this:
function centerPopup(){
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $(".popupContent").height();
var popupWidth = $(".popupContent").width();
$(".popupContent").css({
"position": "fixed",
"top": windowHeight/2-popupHeight/2,
"left": windowWidth/2-popupWidth/2
});
}
This works, except when I need to activate a popup inside of a div tag. It appears way further down, sometimes off the page. I'm assuming it thinks the top of the div tag is the page top.
How can I solve this and make it find the actual main page top?