查阅代码整理(三)之自动修改页面高度

背景:

新增table tr多了之后原有的页面大小将不能展示所有信息,因此需要进行页面高度修改

实现:

这里囊是通过页面定时执行器去执行的,一秒一次实现;

function scrollHeight() {
		var bodyHeight = $('body').height();
		var parentIframe = parent.document.getElementById("MainWorkArea");//MainWorkArea页面id
		var iframeHeight = $(parentIframe).attr("height");
		if (iframeHeight <= bodyHeight) {
			$(parentIframe).attr("height", bodyHeight + 50);
		}

	}
//定时执行器 
setInterval(function () {
        	scrollHeight();
	    }, 1000);

当然也可以放到增加行的方法后面

var parentHeight = parent.document.getElementById("MainWorkArea").height;

parent.document.getElementById("MainWorkArea").height = parseInt(parentHeight)+50;

 

 

其它拓展:

1,获取屏幕的高度和宽度(屏幕分辨率):

window.screen.height

window.screen.width2,

获取屏幕工作区域的高度和宽度(去掉状态栏):

window.screen.availHeight

window.screen.availWidth

3,网页全文的高度和宽度:

document.body.scrollHeight

document.body.scrollWidth

4,滚动条卷上去的高度和向右卷的宽度:

document.body.scrollTop

document.body.scrollLeft

5,网页可见区域的高度和宽度(不加边线):

document.body.clientHeight

document.body.clientWidth

6,网页可见区域的高度和宽度(加边线):

document.body.offsetHeight

document.body.offsetWidth

 

7  获取窗口宽度

if (window.innerWidth)

winWidth = window.innerWidth;

else if ((document.body) && (document.body.clientWidth))

winWidth = document.body.clientWidth;

8  获取窗口高度

if (window.innerHeight)

winHeight = window.innerHeight;

else if ((document.body) && (document.body.clientHeight))

winHeight = document.body.clientHeight;

9 通过深入 Document 内部对 body 进行检测,获取窗口大小

if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)

{

winHeight = document.documentElement.clientHeight;

winWidth = document.documentElement.clientWidth;

}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值