I can not understand what the problem with the work of the code. Everything works fine, until I change the resolution to the iPad (basically any tablet), that is, I don’t twist the screen.
$(window).resize(function(){ if(window.matchMedia && window.matchMedia("(min-width:320px) and (max-width:978px)").matches) { $(".navItem a").click(function(){ $("#nav1").slideUp(); }); } }); It turns out that the code is perfectly processed, if I hold the tablet vertically, it goes into the IF block in the console, it displays the resolution, it gets it perfectly, but if I turn the tablet in a horizontal orientation, we get 1024px resolution, and the code is still processed. This hides the navigation block to me, and I can no longer click on the menu buttons.
Briefly about the essence of the code. I have a menu of the site, which for computers is horizontal at the top, and for mobiles it is hidden behind the "hamburger" icon. Clicking on it vertically crawls down. I have a one-page website concept, so the links are anchor, and there is no website refresh. There is a smooth scroll to the anchor, but it is closed all over this pop-up menu. That is why it should be hidden after clicking on the link. This code that hides below, but for some reason it works even when it should not work. After all, if you run it right away on your computer, it will not start up in the IF block. If you run it from the horizontal mode of the tablet, too, everything is ok, if you turn it into portrait, everything also works with a bang, he sees a decrease in resolution and enters the IF block. But back after the horizontal in portraiture begins to suffer. It stops processing IF, but it just always works, although the condition does not fit.