When you do a project, you often click on a button on the main page, and the right side pops up a div to output the details of the corresponding content. At this point, I want to close the pop-up layer when the mouse clicks out of the pop-up layer, the main idea is :
Find the element that the mouse clicked on
To determine whether this element is in the specified area, it is to determine if its parent element is not a pop-up layer
If you do not hide the pop-up layer, if it is not doing anything
Concrete implementation
The code needs to use jquery, as follows:
$ (document). MouseDown (function (e) {
if ($ (e.target). Parent ("#info"). length==0) {
$ ("#info"). Hide ();
}
)
$ (document). MouseDown (function (e) {})
$ (document) is to get the entire Web document object, similar to the native window.ducument
MouseDown is a mouse event that refers to a similar event when the mouse pointer moves over the element and presses the mouse button:
MouseUp: When you relax the mouse button on the element
MouseOver: When the mouse pointer is over the element
$ (E.target)
$ (E.target) represents the element that gets the click event.
Parent ()
$ (e.target). Parent ("#info"). Length is the parent element that gets the current click event element with the ID info.
The above is a small set of jquery to introduce the realization of click anywhere pop-up layer off the pop-up layer effect, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!