<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
Select the element to check form overflow. Check its style. overflow property, if it is 'visible' then the element is hidden. Also, check if its clientWidth is less then scrollWidth or clientHeight is less then scrollHeight then the element is overflowed.
Check if element is visible in viewport using jquery:If the bottom position of the viewport is greater than the element's top position AND the top position of the viewport is less than the element's bottom position, the element is in the viewport (at least partially).
Answer: Use the jQuery :visible Selector You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.
Another way to check if an element is hidden is to use the window. getComputedStyle() method. It will return the display property value of the object. We can check if the string is equal to none meaning the element is hidden and do something.
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..)
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 :
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With