nav.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var ww = document.body.clientWidth;
  2. $(document).ready(function() {
  3. $(".nav li a").each(function() {
  4. if ($(this).next().length > 0) {
  5. $(this).addClass("parent");
  6. };
  7. })
  8. $(".toggleMenu").click(function(e) {
  9. e.preventDefault();
  10. $(this).toggleClass("active");
  11. $(".nav").toggle();
  12. });
  13. adjustMenu();
  14. })
  15. $(window).bind('resize orientationchange', function() {
  16. ww = document.body.clientWidth;
  17. adjustMenu();
  18. });
  19. var adjustMenu = function() {
  20. if (ww < 800) {
  21. $(".toggleMenu").css("display", "inline-block");
  22. if (!$(".toggleMenu").hasClass("active")) {
  23. $(".nav").hide();
  24. } else {
  25. $(".nav").show();
  26. }
  27. $(".nav li").unbind('mouseenter mouseleave');
  28. $(".nav li a.parent").unbind('click').bind('click', function(e) {
  29. // must be attached to anchor element to prevent bubbling
  30. e.preventDefault();
  31. $(this).parent("li").toggleClass("hover");
  32. });
  33. }
  34. else if (ww >= 800) {
  35. $(".toggleMenu").css("display", "none");
  36. $(".nav").show();
  37. $(".nav li").removeClass("hover");
  38. $(".nav li a").unbind('click');
  39. $(".nav li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() {
  40. // must be attached to li so that mouseleave is not triggered when hover over submenu
  41. $(this).toggleClass('hover');
  42. });
  43. }
  44. }