使用jQuery检测DIV中滚动条的存在? [英] Detecting presence of a scroll bar in a DIV using jQuery?
本文介绍了使用jQuery检测DIV中滚动条的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用jQuery检测DIV中是否存在滚动条。我想使用 $('div')。scrollTop()
但在滚动条位于顶部且没有滚动条的情况下返回0好吧。
I want to detect the presence of a scroll bar in a DIV using jQuery. I was thinking to use $('div').scrollTop()
but that returns 0 in both cases when the scroll bar is at the top and when there is no scroll bar at all.
任何想法的人?
推荐答案
假设<$ div上的c $ c>溢出是 auto
:
var div= document.getElementById('something'); // need real DOM Node, not jQuery wrapper
var hasVerticalScrollbar= div.scrollHeight>div.clientHeight;
var hasHorizontalScrollbar= div.scrollWidth>div.clientWidth;
这篇关于使用jQuery检测DIV中滚动条的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文