jquery检查是否有父div有滚动条 [英] Jquery check if any parent div have scroll bar

查看:90
本文介绍了jquery检查是否有父div有滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查是否有任何父div在jQuery中有滚动条,但我找不到任何好的示例。
这里是我的代码: -

 < div> 
< div class =heading>
< div class =visitor_profile>
< div class =visitor_input_con>
< / div>
< / div>
< / div>
< / div>

我想检查 .visitor_input_con 有滚动条,这里是我的jquery代码: - $ /

$ $ $ $ $ $ $ c $($)$ $ $ $ $ $ $。 hasScrollBar = function(){
return this.get(0).scrollHeight> this.height();
}
})(jQuery);

$('。visitor_input_con')。hasScrollBar();

请帮我解决这个问题。
谢谢

解决方案

您可以过滤父母,例如:

  if($('。visitor_input_con')。parents()。filter(function(){
return $(this).hasScrollBar();
})。length)


I want to check if any parent div have scroll bar in jQuery but I can't find any good example. Here is my code:-

  <div>
     <div class="heading">
        <div class="visitor_profile">
            <div class="visitor_input_con">
            </div>
        </div>
    </div>
</div>

I want to check if any parent of .visitor_input_con has scroll bar here is my jquery code:-

(function($) {
  $.fn.hasScrollBar = function() {
    return this.get(0).scrollHeight > this.height();
  }
})(jQuery);

$('.visitor_input_con').hasScrollBar();

Please help me to solve this issue. Thanks

解决方案

you could filter out parents, e.g:

if($('.visitor_input_con').parents().filter(function(){
    return $(this).hasScrollBar();
}).length)

这篇关于jquery检查是否有父div有滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆