Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery popup/popout menus usability - hide on document click
- <div class="toolbar">
- <div class="popout-wrap">
- <div class="button">
- </div>
- <div class="popout">
- blah blah blah
- </div>
- </div>
- <div class="popout-wrap">
- <div class="button">
- </div>
- <div class="popout">
- blah blah blah
- </div>
- </div>
- ...
- $(".popout-wrap .button").click(function () {
- var menu = $(this).siblings(".popout");
- if (menu.is(":hidden")) {
- $(".popout").not(":hidden").fadeOut("fast");
- menu.css("top", -1 * (menu.outerHeight() + 8) + "px");
- menu.fadeIn("fast");
- } else {
- menu.fadeOut("fast");
- }
- return false;
- });
- $(".popout-wrap .button").blur(function () {
- $(this).siblings(".popout").fadeOut("fast");
- return false;
- });
- //to prevent hiding when clicking on popup but it is not necessary
- //$(".popout-wrap .popout").click()(function(){return false});
- $(document).click(function(){
- var menu = $(".popout-wrap .popout");
- if (!menu.is(":hidden")) {
- menu.fadeOut("fast");
- }
- return false;
- });
Advertisement
Add Comment
Please, Sign In to add comment