click-at-outside
WTF
Detect a click event was outside in a container.
eg: you have a dropmenu, and you want close itself when user click outside the #dropmenu
dom container.
Usage
npm i click-at-outside --save
const cancle = ; // if then event was outdate, you should cancel listen;
Example
menu1 menu2 menu3
;; const $dropmenu = document;const $avatar = document; $avatar; ;
Why not using pure CSS3 :hover for dropmenu?
Pure CSS3 dropmenu was very simple, but it won't close when you tap blank area(mobile device).
Why css('cursor', 'pointer') for body?
In mobile safari, click event usually won't bubbling to document
.
Expect:
- The target element of the event is a link or a form field.
- The target element, or any of its ancestors up to but not including the , has an explicit event handler set for any of the mouse events. This event handler may be an empty function.
- The target element, or any of its ancestors up to and including the document has a cursor: pointer CSS declarations.