[英]Detect vertical scrollbar present or not using JQuery/Javascript
There is an HTML report, where I've applied style as "overflow:auto" The data fills dynamically so I need to detect if there is a
vertical scrollbar existing or not in the report.
有一个HTML报告,其中我已将样式应用为“ overflow:auto” 。数据是动态填充的,因此我需要检测报告中是否存在
垂直滚动条 。 After researching over many forums, which all suggest comparing the
scrollHeight
and clientHeight
, I tried this: 在研究了许多论坛之后,所有这些论坛都建议比较一下
scrollHeight
和clientHeight
,我尝试了一下:
$( document ).ready(function() {
var myReport = document.getElementById("report_id");
if (myReport.scrollHeight > myReport.clientHeight) {
alert("has a scrollbar");
} else {
alert("has NO scrollbar");
}
});
This does not work. 这是行不通的。 The result is always true, ie "has a scrollbar", even when there's no vertical scrollbar.
结果始终为true,即“没有滚动条”,即使没有垂直滚动条也是如此。
Please suggest. 请提出建议。
PS: The above code is just for testing purpose. PS:以上代码仅用于测试目的。
<script>
jQuery(document).ready(function(){
var outerHeight = $("#report_id").outerHeight();
var scrollHeight = $('#report_id')[0].scrollHeight
if (outerHeight < scrollHeight) {
alert("has a scrollbar");
}
else
{
alert("has NO scrollbar");
}
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.