怎么监测当前页面相对于整个页面的高度

怎么监测当前页面相对于整个页面的高度,第1张

function getDocHeight(doc)

{

//在IE中docbodyscrollHeight的可信度最高

//在Firefox中,docheight就可以了

var docHei = 0;

var scrollHei;//scrollHeight

var offsetHei;//offsetHeight,包含了边框的高度

if (docheight)

{

//Firefox支持此属性,IE不支持

docHei = docheight;

}

else if (docbody)

{

//在IE中,只有bodyscrollHeight是与当前页面的高度一致的,

//其他的跳转几次后就会变的混乱,不知道是依照什么取的值!

//似乎跟包含它的窗口的大小变化有关

if(docbodyoffsetHeight) docHei = offsetHei = docbodyoffsetHeight;

if(docbodyscrollHeight) docHei = scrollHei = docbodyscrollHeight;

}

else if(docdocumentElement)

{

if(docdocumentElementoffsetHeight) docHei = offsetHei = docdocumentElementoffsetHeight;

if(docdocumentElementscrollHeight) docHei = scrollHei = docdocumentElementscrollHeight;

}

/

docHei = Mathmax(scrollHei,offsetHei);//取最大的值,某些情况下可能与实际页面高度不符!

/

return docHei;

}

jq不会出现这样的问题的,检查下代码存放位置是否正确。另外您的jq是什么版本的?另外如果实在取不到那就用这个

网页可见区域宽: documentbodyclientWidth

网页可见区域高: documentbodyclientHeight

网页可见区域宽: documentbodyoffsetWidth (包括边线的宽)

网页可见区域高: documentbodyoffsetHeight (包括边线的高)

网页正文全文宽: documentbodyscrollWidth

网页正文全文高: documentbodyscrollHeight

网页被卷去的高: documentbodyscrollTop

网页被卷去的左: documentbodyscrollLeft

网页正文部分上: windowscreenTop

网页正文部分左: windowscreenLeft

屏幕分辨率的高: windowscreenheight

屏幕分辨率的宽: windowscreenwidth

屏幕可用工作区高度: windowscreenavailHeight

屏幕可用工作区宽度: windowscreenavailWidth

。。。。

documentbodyclientWidth 用这个原生的 比jq快得快

网页可见区域宽:documentbodyclientWidth

网页可见区域高:documentbodyclientHeight

网页可见区域宽:documentbodyoffsetWidth (包括边线的宽)

网页可见区域高:documentbodyoffsetHeight (包括边线的宽)

网页正文全文宽:documentbodyscrollWidth

网页正文全文高:documentbodyscrollHeight

网页被卷去的高:documentbodyscrollTop

网页被卷去的左:documentbodyscrollLeft

网页正文部分上:windowscreenTop

网页正文部分左:windowscreenLeft

屏幕分辨率的高:windowscreenheight

屏幕分辨率的宽:windowscreenwidth

屏幕可用工作区高度:windowscreenavailHeight

屏幕可用工作区宽度:windowscreenavailWidth

你所指的应该是网页所见区域高,即documentbodyclientHeight

<html>

<head>

</head>

<body style="height:400px">

<div id="div1">12312</div>

<script type="text/javascript">

documentgetElementById("div1")styleheight=documentbodystyleheight;

alert(documentgetElementById("div1")styleheight);

//如果body,没有设置样式,这个高度就为空

documentgetElementById("div1")styleheight=documentbodyclientHeight

alert(documentgetElementById("div1")styleheight);

//如果设置了样式,offsetHeight就等于样式的height否则等于clientHeight

documentgetElementById("div1")styleheight=documentbodyoffsetHeight

alert(documentgetElementById("div1")styleheight);

</script>

</body>

</html>

您好!很高兴为您答疑!

给您提供一个代码,根据需要稍做修改就可以了,兼容各浏览器:

function getViewSizeWithoutScrollbar(){//不包含滚动条

return {

width : documentdocumentElementclientWidth,

height: documentdocumentElementclientHeight

}

}

function getViewSizeWithScrollbar(){//包含滚动条

if(windowinnerWidth){

return {

width : windowinnerWidth,

height: windowinnerHeight

}

}else if(documentdocumentElementoffsetWidth == documentdocumentElementclientWidth){

return {

width : documentdocumentElementoffsetWidth,

height: documentdocumentElementoffsetHeight

}

}else{

return {

width : documentdocumentElementclientWidth + getScrollWith(),

height: documentdocumentElementclientHeight + getScrollWith()

}

}

}

您可以在火狐社区了解更多内容。希望我的回答对您有所帮助,如有疑问,欢迎继续在本平台咨询。

以上就是关于怎么监测当前页面相对于整个页面的高度全部的内容,包括:怎么监测当前页面相对于整个页面的高度、jquery获取浏览器的宽度和高度怎么做的为啥$(window).width()不行呢、JS如何获取网页除了工具栏以外的高度等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9471451.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存