How about it as a solution
CSS
.parentDivStyle { overflow:hidden; width:300px; height:50px; position:absolute; background:#ccc; float:left; } .childDivStyle { width:100px; height:50px; position:relative; float:left; background:red; border: 1px solid black; }
HTML
<div id="parent" class="parentDivStyle"> <div class="childDivStyle">1</div> <div class="childDivStyle">2</div> <div class="childDivStyle">3</div> <div class="childDivStyle">4</div> <div class="childDivStyle">5</div> </div>
Javascript
function getNotVisible(parentId, childClassName) { var parent = document.getElementById(parentId), children, elements; if (parent) { children = parent.getElementsByClassName(childClassName); if (children) { elements = []; Array.prototype.forEach.call(children, function (child) { var pBounds = parent.getBoundingClientRect(), cBounds = child.getBoundingClientRect(); if (cBounds.right < pBounds.left || cBounds.left > pBounds.right || cBounds.bottom < pBounds.top || cBounds.top > pBounds.bottom) { elements.push(child); } }); } } return elements; } console.log(getNotVisible("parent", "childDivStyle"));
Jsfiddle on
BTW, if you need a jquery object from this, do the following
var $hiddens = $(getNotVisible("parent", "childDivStyle"));
In addition, if you want the returned array, not undefined, that is, silently if the parent is not or no children are found.
Then remove
elements = [];
And change
var parent = document.getElementById(parentId), children, elements = [];
And, of course, it all depends on whether you set up your CSS correctly, since checks are not performed for visibility or overflow , etc.
If you want to add CSS checks to double-check CSS, you can use window.getComputedStyle and check important values.
Xotic750
source share