Created
February 5, 2017 19:18
-
-
Save Lokua/ecee73d92b780714cd194d77b31b10fd to your computer and use it in GitHub Desktop.
Detect if DOM event happened within a bounding box. Useful for outside click detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function isEventWithin(e, element) { | |
const rect = element.getBoundingClientRect() | |
return ( | |
rect.top <= e.clientY && | |
e.clientY <= rect.top + rect.height && | |
rect.left <= e.clientX && | |
e.clientX <= rect.left + rect.width | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment