jQuery Menus Acting Buggy on Mobile Devices

jQuery Menus Acting Buggy on Mobile Devices

I'm working on a test site which can be found here: https://devwww.interfacett.com

The menu functionality works fine at any size on a desktop computer, but when I switch to my iPhone the mobile menu gets really buggy. Notably when you click open one of the accordion menus and then use your finger to scroll down the page, it automatically closes the menu.

Try it on your phone and you'll see what I mean.

The mobile menus uses this code for the functionality:

  • jQuery(document).ready(function(){
    1.     function resizeForm(){
    2.         var width = (window.innerWidth > 0) ? window.innerWidth : document.documentElement.clientWidth;
    3.         if(width > 1024){

    4.         } else {
    5. function accordion_menus(){
    6. // if we are not on mobile (menu icon is hidden) show sub items and bail
    7. console.log('debug: start');
    8. if ( jQuery('#primary-navigation .menu-toggle').is(':hidden') ){
    9. console.log('debug: yes, it is hidden');
    10. // show sub menus
    11. $('#primary-navigation ul.nav-menu ul.sub-menu').show();
    12. return;
    13. } else{
    14. // hide sub menus
    15. $('#primary-navigation ul.nav-menu ul.sub-menu').hide();
    16. }
    17. // top level nav click function
    18. $('#primary-navigation ul.nav-menu > li > a').click(function(e){
    19. // store parent li to variable
    20. var parent_li = $(this).parent('li');
    21. // if sub menu does not exist in parent li
    22. if ( !$('ul.sub-menu', parent_li).first().length ) {
    23. return;
    24. }
    25. // if sub menu is already active, bail
    26. if ( parent_li.hasClass('sub-menu-active') ){
    27. parent_li.find('ul').slideUp(100, function(parent_li){
    28. });
    29. parent_li.removeClass('sub-menu-active');  
    30. return false;
    31. }
    32. // stop link click
    33. e.preventDefault();
    34. // store current sub menu in variable
    35. var current_submenu = $('ul.sub-menu', parent_li).first();
    36. // slide up non-current sub menus
    37. $('#primary-navigation').find('ul.sub-menu').not(current_submenu).slideUp(function(parent_li){
    38. // remove sub-menu-active class from all first level items except current parent li
    39. $('#primary-navigation').find('li').not(parent_li).removeClass('sub-menu-active');
    40. });
    41. // slide down current sub menu
    42. current_submenu.slideDown(100, function(){
    43. // add sub-menu-active to current parent li
    44. parent_li.addClass('sub-menu-active');
    45. });
    46. });
    47. // second level nav click function
    48. jQuery('#primary-navigation ul.nav-menu ul.sub-menu > li > a').click(function(e){
    49. // store parent li to variable
    50. var parent_li = jQuery(this).parent('li');
    51. // if sub menu does not exist in parent li
    52. if ( !jQuery('ul.sub-menu', parent_li).first().length ) {
    53. return;
    54. }
    55. // if sub menu is already active, bail
    56. if ( parent_li.hasClass('sub-menu-active') ){
    57. parent_li.find('ul').slideUp(100, function(){
    58. // remove sub-menu-active class from all first level items except current parent li
    59. });   
    60. parent_li.removeClass('sub-menu-active');  
    61. return false;
    62. }
    63. // stop link click
    64. e.preventDefault();
    65. // store current sub menu in variable
    66. var current_submenu = jQuery('ul.sub-menu', parent_li).first();
    67. // slide up non-current sub menus
    68. jQuery('#primary-navigation ul.nav-menu ul.sub-menu > li > ul.sub-menu').not(current_submenu).slideUp(function(){
    69. // remove sub-menu-active class from all second level items except current parent li
    70. jQuery('#primary-navigation ul.nav-menu ul.sub-menu > li').not(parent_li).removeClass('sub-menu-active');
    71. });
    72. // slide down current sub menu
    73. current_submenu.slideDown(100, function(){
    74. // add sub-menu-active to current parent li
    75. parent_li.addClass('sub-menu-active');
    76. });
    77. });
    78. }
    79. // load menu accordion on doc ready
    80. jQuery(document).ready(function($) {
    81. accordion_menus();
    82. });
    83. // load menu accordion on window resize
    84. jQuery(window).resize(function(){
    85. accordion_menus();
    86. });
    87.         }    
    88.     }
    89.     window.onresize = resizeForm;
    90.     resizeForm();
    91. });

    I'm not sure what I'm doing wrong here, but I'm hoping someone can chime in and tell me what I'm missing. I can't seem to figure it out.

    Thanks in advance, I really appreciate it!