(function getCoords() { let tCoords = tC1.getBoundingClientRect(), txCoords = txC1.getBoundingClientRect(), mCoords = mC1.getBoundingClientRect(), elCoords = ele1.getBoundingClientRect(); function intersectRect(a, b) { return Math.max(a.left, b.left + 40) < Math.min(a.right, b.right - 40) && Math.max(a.top, b.top + 40) < Math.min(a.bottom, b.bottom - 40); } // can't do if/else because sometimes they both come out at once // and one of them will be ignored if (intersectRect(tCoords, elCoords)) { getHitTestIncrease(); } if (intersectRect(txCoords, elCoords)) { getHitTestDecrease(); } if (intersectRect(mCoords, elCoords)) { getHitTestMargarita(); } requestAnimationFrame(getCoords); }());