JSFiddle - React, Tailwind, and code Playground
by Graham Fairweather
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>
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;
}
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"));