I have some code that acts as a click toggle for a menu. I only want the code to run if the window width is under 768px, so I wrapped it in an if statement, that calculates the window width. I bound this function to the page resize event and page ready. It works some of the time but not others. Resize the results panel a few times and you’ll see what I mean…
Share
Not the key issue, but:
jQuery("#nav-btn a.togglemenu")should bejQuery("#nav a.togglemenu")You’ve added the click handler inside the
aaMenusfunction, so this line:…is running the function, and adding a new click hander, every time the window is resized. If the click handler has been added an even number of times, you’re toggling on and off at the same time, with no visible result. Even if it’s been added an odd number of times, you’re running the toggle up to hundreds of times in a row, resulting in a huge delay.
All you need to do is take that click event handler out of your function:
http://jsfiddle.net/mblase75/LyUzr/10/