Im trying to detect if two of my div overlap. I have a div that contains a block of text, that div can be expaned and minified with buttonclick. Underneth that is another div that will be filled with "things" until a certain point it will turn in to a scroll list. Now to the tricky part.
This work well until the list get filled to max (which I cant change) or on an tablet 7".
So Iam trying to write a method that can detect if the two divs overlap. I cant find a good solution for this anywhere, mabey there is none or mabey Im not searching on the right things, either way I need help.
This is what i have tried so far:
crashDetection(event, pageInfoBlock) {
let helBlockTop = parseInt(document.getElementById('page-info').getBoundingClientRect().bottom, 10);
let helBlockBottom = parseInt(document.getElementById('page-info').getBoundingClientRect().height, 10);
let containerBottom = parseInt(document.getElementById('bottomContainer').getBoundingClientRect().top, 10);
if (helBlockTop + helBlockBottom > containerBottom && containerBottom !== 0) {
console.log("It overlap");
}
}
This works.. almost because in some situations when i scroll down the div containing the whole thing get stretcht out so it looks good.. but if I scroll to the top again they overlap.. and my method detect overlaping even if there is none..
So my question is how do I detect if two div overlap? No JQuery please and sorry for my bad english.. :P