我想在屏幕中心(水平和垂直)打開一個div。爲什麼我的容器沒有進入中心
var documnetWidth = $(document).width(),
documentHeight = $(document).height(),
widgetFormHeight = widgetForm.height(),
widgetFormWidth = widgetForm.width();
widgetForm.css({
top: documentHeight/2 - widgetFormHeight/2,
left: documnetWidth/2 - widgetFormWidth/2
});
我的小部件水平居中但垂直需要一些偏移。
$(窗口)不能解決它。 –
如果確定,他可以嘗試固定位置,或者按照建議使用scrollTop。 – sabithpocker
答案已更新,以便按照演示允許當前文檔的滾動狀態。或者'position:fixed'會按照sabithpocker的建議來做(我最初沒有想到,因爲我太習慣於支持某個必須在IE6中運行的應用程序)。 – nnnnnn