function getWindowDimensions() {
var winWidth = 0;
var winHeight = 0;
//獲取窗口寬度
if (window.innerWidth) {
winWidth = window.innerWidth;
}
else if ((document.body) && (document.body.clientWidth)) {
winWidth = document.body.clientWidth;
}
//獲取窗口高度
if (window.innerHeight) {
winHeight = window.innerHeight;
}
else if ((document.body) && (document.body.clientHeight)) {
winHeight = document.body.clientHeight;
}
//通過深入Document內部對body進行檢測,獲取窗口大小
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}
var sizeObj = new Object();
sizeObj.width = winWidth;
sizeObj.height = winHeight;
return sizeObj;
}
function toResetWinSize() {
var winSize = getWindowDimensions();
var footerPanelHeight = $("#panelFooter").height();
var rightPanelHeight = $("#panelRight").height();
var leftPanelHeight = 0;
var minLeftPanelHeight = $("#leftMenuContainer").height() + 60;
leftPanelHeight = rightPanelHeight > winSize.height - footerPanelHeight ? rightPanelHeight : winSize.height - footerPanelHeight;
leftPanelHeight = leftPanelHeight < minLeftPanelHeight ? minLeftPanelHeight : leftPanelHeight;
$("#panelLeft").css({ "height": leftPanelHeight });
$("#panelRight").css({ "width": winSize.width - 250 - 24 });
}
$(document).ready(function () {
toResetWinSize();
window.setInterval(toResetWinSize, 1000);
});
$(window).resize(function () {
toResetWinSize();
});
JS獲取窗口寬度高度
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.