[英]how to check if overflow:hidden html class has cut out from view content using jquery or javascript?
<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>
this doesnt work 这不起作用
We wrap the contents in a div so we can get a height from it and compare to the .scrollable
height ( which is not scrollable.. ) 我们将内容包装在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;
}
demo http://jsfiddle.net/gaby/ApZP2/ 演示http://jsfiddle.net/gaby/ApZP2/
Using javascript and if div has id then 使用javascript,如果div有id,那么
<div id="scrollable" class="scrollable" style="overflow: hidden"> </div>
function check_string_is_hidden_due_to_overflow(div_id) {
var s_h = document.getElementById(div_id).scrollHeight;
var c_h = document.getElementById(div_id).clientHeight;
if(s_h != c_h) {
return true; // Means some content is hidden due to overflow hidden
} else {
return false; // Whole content is displayed.
}
}
check_string_is_hidden_due_to_overflow("scrollable"); check_string_is_hidden_due_to_overflow( “滚动”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.