I have a calendar that has list of events per day. Currently I show a maximum of 3 events per day and allow the user to toggle to expand the list.
I hide the list with overflow:hidden and max-height:XXpx property. I am trying to detect the events that are currently hidden within that list.
I've looked around and cant find anything that detects this specifically
I have tried:
if (element.offsetHeight < element.scrollHeight || element.offsetWidth < element.scrollWidth) {
// element has overflow value
} else {
// element doesn't have overflow value
}
and both element.offsetHeight
& element.scrollHeight
return the same value for any of the elements in my list.
To check if an element is hidden or not, jQuery :hidden selector can be used. .toggle() function is used to toggle the visibility of an element.
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.
scrollHeight
and scrollWidth
are DOM properties, not jQuery.
$('div').each(function() {
// get scroll measurements from DOM element
var contentHeight = this.scrollHeight;
var contentWidth = this.scrollWidth;
// get the visible measurements from jQuery object
var $this = $(this);
var visibleHeight = $this.height();
var visibleWidth = $this.width();
if (visibleHeight < contentHeight
|| visibleWidth < contentWidth ) {
// element has overflow value
} else {
// element doesn't have overflow value
}
})
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