![](/img/trans.png)
[英]Freeze vertical Scrollbar In a relative div using JQuery or Javascript
[英]Detect vertical scrollbar present or not using JQuery/Javascript
有一个HTML报告,其中我已将样式应用为“ overflow:auto” 。数据是动态填充的,因此我需要检测报告中是否存在垂直滚动条 。 在研究了许多论坛之后,所有这些论坛都建议比较一下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");
}
});
这是行不通的。 结果始终为true,即“没有滚动条”,即使没有垂直滚动条也是如此。
请提出建议。
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.