原文鏈接:https://my.oschina.net/jingyao/blog/776603
此方法為解決頁面含有滾動條時,彈窗位置錯誤問題,此方法可將帶滾動條頁面中彈窗顯示於頁面中間。
$("#dialogID").panel("move",{top:$(document).scrollTop()+($(window).height()-height)*0.5});
或者
$('#dlgDetail').window('open').window('resize', { width: '250px', height: '500px', top: sh + ($(window).height() - 500) * 0.5 });
說明:
(1)height:dialog的高度。
(2)移動dialog有現成的函數,但是dialog本身沒有move函數,但是dialog是繼承自panel的,panel有move函數,因此可以調用panel的move函數來移動dialog。使用時,先將dialog打開,后移動即可。
備注:
(1)$(window).height(); //獲取瀏覽器顯示區域的高度
(2)$(document.body).height(); //獲取頁面的文檔高度
(3)$(document).scrollTop(); //獲取滾動條到頂部的垂直高度
轉載於:https://my.oschina.net/jingyao/blog/776603