<div class="scrollable" style="overflow: hidden"> </div>
$(function() {
if($(".scrollable").hasElementsInsideItThatAreCutOffByOverflowHidden == false){
$(".scrollable").scrollable({ vertical: true, mousewheel: true });
}
}
<a onClick="isHidingMyStuff"> check if your stuff is hidden <a>
这行不通
最佳答案
我们将内容包装在一个 div 中,以便我们可以从中获取高度并与 .scrollable
高度进行比较(不可滚动..)
function isHidingMyStuff(){
var $s = $('.scrollable');
$s.wrapInner('<div />'); // wrap inner contents
var hidden = $s.height() < $s.children('div').height();
$s.children('div').replaceWith( $s.children('div').html() ); //unwrap
return hidden;
}
演示:
function isHidingMyShit() {
var $s = $('.scrollable');
$s.wrapInner('<div />'); // wrap inner contents
var hidden = $s.height() < $s.children('div').height();
$s.children('div').replaceWith($s.children('div').html()); //unwrap
return hidden;
}
.scrollable {
height: 50px;
margin-bottom: 10px;
border: 1px solid #ccc;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="scrollable" style="overflow:hidden;">
test testtest testtest testtest<br /> testtest testtest testtest testtest<br /> testtest testtest testtest testtest<br /> testtest test TOST
</div>
<a href="#" onClick="alert(isHidingMyShit())"> check if your shit is hidden <a>
关于javascript - 如何检查是否溢出:hidden html class has cut out from view content using jquery or javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4809738/