Advertisement
Ranga14

DFW Door Responsive JS

Jan 17th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.    
  3.     $("#menu-icon").click(function() {
  4.        
  5.         $("#navigation").show();
  6.        
  7.         // Close the Navigation whenever you click out of the container.
  8.         $(document).mouseup(function (e)
  9.         {
  10.             var $container = $("#navigation");
  11.            
  12.             if (!$container.is(e.target) // if the target of the click isn't the container...
  13.                 && $container.has(e.target).length === 0) // ... nor a descendant of the container
  14.             {
  15.                 $container.hide();
  16.             }
  17.         });
  18.        
  19.     });
  20.    
  21.     // Optimalisation: Store the references outside the event handler:
  22.     var $window = $(window);
  23.  
  24.     function checkWidth() {
  25.         var windowsize = $window.width();
  26.         if (windowsize >= 800) {
  27.             // If the window is greater than 800px wide then remove the Navigation style attribute.
  28.             $("#navigation").removeAttr("style");
  29.             // Unbind the pesky mouseup event above. :)
  30.             $(document).unbind();
  31.         }
  32.     }
  33.     // Execute on load
  34.     checkWidth();
  35.     // Bind event listener
  36.     $(window).resize(checkWidth);
  37.  
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement