Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $("#menu-icon").click(function() {
- $("#navigation").show();
- // Close the Navigation whenever you click out of the container.
- $(document).mouseup(function (e)
- {
- var $container = $("#navigation");
- if (!$container.is(e.target) // if the target of the click isn't the container...
- && $container.has(e.target).length === 0) // ... nor a descendant of the container
- {
- $container.hide();
- }
- });
- });
- // Optimalisation: Store the references outside the event handler:
- var $window = $(window);
- function checkWidth() {
- var windowsize = $window.width();
- if (windowsize >= 800) {
- // If the window is greater than 800px wide then remove the Navigation style attribute.
- $("#navigation").removeAttr("style");
- // Unbind the pesky mouseup event above. :)
- $(document).unbind();
- }
- }
- // Execute on load
- checkWidth();
- // Bind event listener
- $(window).resize(checkWidth);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement