gpt4 book ai didi

javascript - Jquery 检查是否有父 div 有滚动条

转载 作者:太空狗 更新时间:2023-10-29 14:09:41 24 4
gpt4 key购买 nike

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

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

我想检查 .visitor_input_con 的任何父级是否有滚动条这是我的 jquery 代码:-

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

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

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

最佳答案

您可以过滤掉 parent ,例如:

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

关于javascript - Jquery 检查是否有父 div 有滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27875195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com