检测DIV是否有滚动条 [英] Detect if the DIV have scroll bar or not
本文介绍了检测DIV是否有滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
使用jQuery在DIV中检测滚动条的存在?
有以下标记:
<div class="content">Lorem</div>
<div class="content">Lorem Iorem Lorem Iorem Lorem Iorem Lorem Iorem Lorem IoremLorem Iorem Lorem Iorem Lorem Iorem</div>
<div class="content">Lorem</div>
<div class="content">Lorem</div>
如果内容有滚动条,那么应该向div添加类scroll-image。
If content have scroll bar, then it should add class to that div like "scroll-image".
DIV的高度可以不同。任何jQuery解决方案。
Height can be different for DIVs. Any jQuery solution for this.
推荐答案
(function($) {
$.fn.hasScrollBar = function() {
return this.get(0).scrollHeight > this.height();
}
})(jQuery);
$('#my_div1').hasScrollBar(); // returns true if there's a `vertical` scrollbar, false otherwise..
=http://stackoverflow.com/questions/4814398/jquery-check-if-scrollbar-visible-div-with-overflowauto> Jquery - 检查:如果滚动条可见(div带溢出:自动)
Taken from Jquery - Check: If scrollbar visible (div with overflow:auto)
这篇关于检测DIV是否有滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文