简体   繁体   English

jQuery弹出/隐藏框

[英]jQuery popup / hide box

Here is where I am at so far: http://jsbin.com/ujuqa3/4 这是我到目前为止的位置: http : //jsbin.com/ujuqa3/4

So far, I've decided to set a variable to false and to true when the .share-box is open. 到目前为止,我已经决定在.share-box打开时将变量设置为false和true。 After it is open, I want the user to be able to click anywhere (except the box) to close it. 打开后,我希望用户能够单击任何地方(框除外)将其关闭。

Right now it works the first time, but any time after that, it messes up for some reason. 目前,它是第一次运行,但是此后的任何时间,由于某种原因,它都会混乱。

    $(document).ready(function() {

        // user clicks on report this button
       $(".shareThis").click(function() {

        // confirmation fades in
        $(".share-box").fadeIn("fast"),

                // Prevent events from getting pass .share-box
                $(".share-box").click(function(e){
                  e.stopPropagation();
                });
       });

      $(document.body).click(function () {
                $("body").click(function(){
                    // hide the share-box if clicked anywhere aside from the box itself
                  $(".share-box").fadeOut().removeClass("active");
                });
  });
     });

Add the return false; 添加return false;

  // user clicks on report this button
   $(".shareThis").click(function() {

  // confirmation fades in
      $(".share-box").fadeIn(),

      // Prevent events from getting pass .share-box
      $(".share-box").click(function(e){
        e.stopPropagation();
      });

 return false;
   });

When $('.shareThis') click happen its also triggering the $(document.body).click 当$('。shareThis')单击发生时,也会触发$(document.body).click

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM