Home > Web Front-end > JS Tutorial > body text

jquery implements the method of hiding the drop-down div and mask layer when clicking on other areas_jquery

WBOY
Release: 2016-05-16 15:24:05
Original
1336 people have browsed it

The example in this article describes how jquery implements hiding the drop-down div and mask layer when clicking on other areas. Share it with everyone for your reference, the details are as follows:

For a better user experience, when doing a drop-down to obtain other pop-up layers, when expanding the drop-down, click on other areas to automatically hide the collapse drop-down and mask layers. This effect uses a piece of js That's it.

The following picture is an example of a drop-down menu for reference:

Effect implementation source code:

$(document).bind('click', function(e) {
  var e = e || window.event; //浏览器兼容性
  var elem = e.target || e.srcElement;
  while (elem) {
    //循环判断至跟节点,防止点击的是div子元素
    if (elem.id && elem.id == 'menu') {
      return;
    }
    elem = elem.parentNode;
  }
  //点击的不是div或其子元素
  $('.menuList,.overlay').hide();
});

Copy after login

I hope this article will be helpful to everyone in jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template