Javascript 如何检查页面上是否存在垂直阴囊?
要检查页面是否有我使用的滚动条,请执行以下操作:Javascript 如何检查页面上是否存在垂直阴囊?,javascript,jquery,Javascript,Jquery,要检查页面是否有我使用的滚动条,请执行以下操作: <script> if (document.body.scrollWidth > document.body.offsetWidth){alert('exist');} </script> 如果(document.body.scrollWidth>document.body.offsetWidth){alert('exist');} 但它不起作用 如何检查页面上是否存在滚动条?您可以检查文档的滚动高度: if(
<script>
if (document.body.scrollWidth > document.body.offsetWidth){alert('exist');}
</script>
如果(document.body.scrollWidth>document.body.offsetWidth){alert('exist');}
但它不起作用
如何检查页面上是否存在滚动条?您可以检查文档的
滚动高度
:
if($(document.body)[0].scrollHeight > $(window).height()){
alert('vertical scroll exists.');
}
一个简单的测试场景: css: 所以js是这样的:
if($('body')[0].scrollHeight > $(window).height()){
alert('vertical scroll exists.');
}
或
此处$('body')[0]。滚动高度
您需要选择文档的正文
$(document.body)[0]。也可以使用$(document.height()
注:
$(选择器)[0]。scrollHeight
小于的IE 8.0版不支持此选择器。此答案是否有帮助?谢谢您的帮助,我看不到。您为什么使用$(文档)[0]。scrollHeight
而不是$(文档)。height()
?
if($('body')[0].scrollHeight > $(window).height()){
alert('vertical scroll exists.');
}
if($(document.body)[0].scrollHeight > $(window).height()){
alert('vertical scroll exists.');
}