Alpine JS magic helper that determines when elements overlap or intersect each other, perfect for menus, tooltips, modals, and collision detection 🥞
npm install alpinejs-overlap> [!IMPORTANT]
> This plugin is no longer maintained or supported.




A lightweight Alpine JS plugin that adds an $overlap() utility to detect when
DOM elements overlap each other.
- 🔍 Provides a global $overlap() method that returns true or false when
checking if elements intersect
- 🧩 Simple to use API by calling $overlap('#targetElement') to detect element
intersections
- Create UI components that react to element overlaps
- Build drag-and-drop interfaces
- Position tooltips/dropdowns to avoid collisions
- Implement simple collision detection for interactive elements
``html
defer
src="https://unpkg.com/alpinejs-overlap@latest/dist/cdn.min.js"
>
`
`shell`
yarn add -D alpinejs-overlap
npm install -D alpinejs-overlap
`js
import Alpine from 'alpinejs'
import overlap from 'alpinejs-overlap'
Alpine.plugin(overlap)
Alpine.start()
`
` html
:class="{ 'bg-green-700': elementsAreOverlapping, 'bg-gray-900': !elementsAreOverlapping }"
class="absolute inset-y-0 right-0 size-96 grid place-content-center text-white"
@resize.window="elementsAreOverlapping = $overlap('#TargetEl')"
>