Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 2.33 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jquery hide dropdown when click anywhere but menu
  2. $(document).click(function(event) {
  3.     if ($(event.target).parents().index($('.notification-container')) == -1) {
  4.         if ($('.notification-container').is(":visible")) {
  5.             $('.notification-container').animate({
  6.                 "margin-top": "-15px"
  7.             }, 75, function() {
  8.                 $(this).fadeOut(75)
  9.             });
  10.         }
  11.         else {
  12.             //This should only show when you click: ".notification-button" not document
  13.             $('.notification-container').show().animate({
  14.                 "margin-top": "0px"
  15.             }, 75);
  16.  
  17.         }
  18.     }
  19. });
  20.        
  21. $('.drop-down').click(function () {
  22.     // The code to open the dropdown
  23.  
  24.     $('body').click(function () {
  25.         // The code to close the dropdown
  26.     });
  27. });
  28.        
  29. $(':not(#country)').click(function() {
  30.      $('#countrylist').hide();
  31. }
  32.        
  33. $('body').click(function(e){
  34.   if($(e.target).closest('.notification-container').length === 0){
  35.     // close/animate your div
  36.   }
  37. });
  38.        
  39. $(document).click(function(event) {
  40.  
  41. if($(event.target).parents().index($('.notification-container')) == -1) {
  42.     if($('.notification-container').is(":visible")) {
  43.         $('.notification-container').animate({"margin-top":"-15px"}, 75, function({$(this).fadeOut(75)});
  44.     }  
  45. }        
  46. });
  47.  
  48. $(".notification-button").click(function(event){
  49.     event.stopPropagation();
  50.     $('.notification-container').show().animate({"margin-top":"0px"}, 75);
  51. });
  52.        
  53. $(document).click(function(e) {
  54.  
  55.     var isModalBox = (e.target.className == 'modal-box');
  56.  
  57.     if (!isModalBox) {
  58.         $('.modal-box:visible').animate({
  59.             "margin-top": "-15px"
  60.         }, 75, function() {
  61.             $(this).fadeOut(75);
  62.         });
  63.     }
  64. });
  65.  
  66. $('a').click(function(e) {
  67.     e.stopPropagation(); // Important if you´d like other links to work as usual.
  68. });
  69.  
  70. $('#temp-button').click(function(e) {
  71.     e.preventDefault();
  72.     $('.modal-box').show().animate({
  73.         "margin-top": "0px"
  74.     }, 75);
  75. });
  76.        
  77. $(document).ready(function(){
  78.     $(".notification-button").click(function(){
  79.         $('.notification-container').toggle().animate({"margin-top":"0px"}, 75);
  80.     });
  81.  
  82.     $('.notification-wrapper').bind('clickoutside', function (event) {
  83.         $('.notification-container').animate({"margin-top":"-15px"}, 75, function(){$(this).fadeOut(75)});
  84.     });
  85. });