天天看點

在Jquery中讓一個容器div顯示在螢幕正中央

非常簡單就實作了,代碼不用解釋,很容易懂的   

//request data for centering

var windowWidth = document.documentElement.clientWidth;

var windowHeight = document.documentElement.clientHeight;

var popupHeight = $("#popupContact").height();

var popupWidth = $("#popupContact").width();

//centering

$("#popupContact").css({

    "position": "absolute",

    "top": windowHeight/2-popupHeight/2,

    "left": windowWidth/2-popupWidth/2

});