获取带滚动条的页面的位置,长宽等信息

转自

http://zhidao.baidu.com/link?url=2NZqkma2IoWC2tK3lK-6btiktAWItFVw6VSjDOKzYbOTrP4Ab0wp-r1sEz7Mzr_pOoRKNBUw993TKuJ3ox0MVh1P-ydxu6pMwdSgRYzUfRC

很有用

这样可以按照自己的要求进行定位


strInfo+=\r\n网页可见区域高:+document.body.clientHeight;
strInfo+=\r\n网页可见区域宽:+document.body.offsetWidth+(包括边线的宽);
strInfo+=\r\n网页可见区域高:+document.body.offsetHeight+(包括边线的高);
strInfo+=\r\n网页正文全文宽:+document.body.scrollWidth;
strInfo+=\r\n网页正文全文高:+document.body.scrollHeight;
strInfo+=\r\n网页被卷去的高:+document.body.scrollTop;
strInfo+=\r\n网页被卷去的左:+document.body.scrollLeft;
strInfo+=\r\n网页正文部分上:+window.screenTop;
strInfo+=\r\n网页正文部分左:+window.screenLeft;
strInfo+=\r\n屏幕分辨率的高:+window.screen.height;
strInfo+=\r\n屏幕分辨率的宽:+window.screen.width;
strInfo+=\r\n屏幕可用工作区高度:+window.screen.availHeight;
strInfo+=\r\n屏幕可用工作区宽度:+window.screen.availWidth;
window.confirm(strInfo);
</script
-----------------------------------------------------------------------------------------
最近编程中发现html静态页面的开发可以使用
document.body.ClientHeight
来获得页面的高度,但asp.net的页面却无法这样获取,获取到的只是页面最小的高度,比如页面只有一个button,那么该js语句获得的就是24。
document.documentElement.OffsetHeight
----------------------------------------------------------------------------------------加上document.body.scrollLeft;
document.body.scrollTop;
x=document.body.clientWidth+document.body.scrollLeft;
y=document.body.clientHeight+document.body.scrollTop;若想得到整个页面的高度可以用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <script type="text/javascript"> function GetPageSize() { var scrW, scrH; if(window.innerHeight && window.scrollMaxY) { // Mozilla scrW = window.innerWidth + window.scrollMaxX; scrH = window.innerHeight + window.scrollMaxY; } else if(document.body.scrollHeight > document.body.offsetHeight) { // all but IE Mac scrW = document.body.scrollWidth; scrH = document.body.scrollHeight; } else if(document.body) { // IE Mac scrW = document.body.offsetWidth; scrH = document.body.offsetHeight; } var winW, winH; if(window.innerHeight) { // all except IE winW = window.innerWidth; winH = window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // IE 6 Strict Mode winW = document.documentElement.clientWidth; winH = document.documentElement.clientHeight; } else if (document.body) { // other winW = document.body.clientWidth; winH = document.body.clientHeight; } // for small pages with total size less then the viewport var pageW = (scrW<winW) ? winW : scrW; var pageH = (scrH<winH) ? winH : scrH; return {PageW:pageW, PageH:pageH, WinW:winW, WinH:winH}; } function GetPageScroll() { var x, y; if(window.pageYOffset) { // all except IE y = window.pageYOffset; x = window.pageXOffset; } else if(document.documentElement && document.documentElement.scrollTop) { // IE 6 Strict y = document.documentElement.scrollTop; x = document.documentElement.scrollLeft; } else if(document.body) { // all other IE y = document.body.scrollTop; x = document.body.scrollLeft; } return {X:x, Y:y}; } function main() { var div = document.getElementById("div"); for(var i=0; i<200; i++) { document.body.appendChild(document.createTextNode("Hello, World!")); document.body.appendChild(document.createElement("br")); } var sz = GetPageSize(); alert([sz.PageW,sz.PageH,sz.WinW,sz.WinH].join(", ")); window.scrollTo(0, 1500); var sl = GetPageScroll(); alert([sl.X,sl.Y].join(", ")); } </script> </head> <body onload="main();"> </body> </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值