jquery Implementation Click any position pop-up layer off the pop-up layer effect _jquery

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.