开发者

Exit dynamic popup by clicking outside of it?

开发者 https://www.devze.com 2023-03-07 11:50 出处:网络
I have a popup where i basically just dim the body giving it the lights out effect. I have a click handeler where if the body is clicked it will close the popup but my issue is the click handler stops

I have a popup where i basically just dim the body giving it the lights out effect. I have a click handeler where if the body is clicked it will close the popup but my issue is the click handler stops all clicks even before the popup is opened. Does anyone know how i could do this so that clicking on a link before the popup is opened would go to the link but clicking one after the popup was opened would do my function and not click the link?

Heres what i use right now:

   $(document).ready(function() {
     $("body").click(function(){
                var element=document.getElementById("game"); 
//yes i could use the jquery method for all of these but this works


                element.width="650";
                element.height="500";
                element.style.position="rela开发者_如何转开发tive";
                $("body").fadeTo(3000,1.0);
            }
            return false;
        })
    });


You can actually add your "body" click handeler only after clicking your link/opening the popup. Then after clicking the "body" you may remove it again and restore the click handler for your link. "bind()" and "unbind()" will be handy.

K


Where's the jQuery? When you use jQuery, you use jQuery...

When you click on the body, you can check whether #game is visible or not and work with that:

$(document).ready(function() {
  $('body').click(function(e){
    if (!$('#game').is(':visible')) {
      $('#game').width('650px');
      $('#game').height('500px');
      $('#game').css('position', 'relative');

      $('body').fadeTo(3000, 1.0);

      e.preventDefault();
      return false;
    }
  });
});
0

精彩评论

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