ページの中央にポップアップするjsポップアップがあります。問題は、ユーザーがページの一番下までスクロールし、ボタンをクリックしてポップアップをトリガーすると、ポップアップが画面の中央ではなく上部に表示されることです (ユーザーは既に下にスクロールしているため、まだページの真ん中にはありません)。
私が望むのは、ユーザーがどこを見ているかに関係なく、ポップアップはユーザーの画面の中央に表示されることです。
function centerPopup(){
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $(".popupContent").height();
var popupWidth = $(".popupContent").width();
$(".popupContent").css({
"position": "absolute",
"top": windowHeight/2-popupHeight/2,
"left": windowWidth/2-popupWidth/2
});
//this is needed for ie6
$(".backgroundPopup").css({ "height": windowHeight });
}
または、ポップアップをトリガーするボタンの下にポップアップを表示することは可能ですか?