开发者

jQuery popup / hide box

Here is where I am at so far: 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. 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.stopP开发者_如何学运维ropagation();
                });
       });

      $(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;

  // 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


build a demo at

http://jsbin.com/uyizi4/4

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜