是否可以检查overflow:auto
一个 div 的?
例如:
HTML
<div id="my_div" style="width: 100px; height:100px; overflow:auto;" class="my_class">
* content
</div>
JQUERY
$('.my_class').live('hover', function (event)
{
if (event.type == 'mouseenter')
{
if( ... if scrollbar visible ? ... )
{
alert('true'):
}
else
{
alert('false'):
}
}
});
有时内容很短(没有滚动条),有时很长(滚动条可见)。
一个小插件。
(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..
已测试可在 Firefox、Chrome、IE6、7、8 上运行
但无法正常工作body
标签选择器
demo http://jsfiddle.net/reigel/p3FFL/
Edit
我发现当水平滚动条导致垂直滚动条出现时,此功能不起作用......
我找到了另一个解决方案...使用clientHeight
return this.get(0).scrollHeight > this.get(0).clientHeight;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)