I'm having an issue with a responsive menu I've been working on for some of my designed sites. The jQuery part of it is made to show or hide the menu depending on window width (and hide/show a bar to toggle it).

In mobile browsers, the toggled-open menu will close again when you scroll -- but only if the address bar has been hidden or shown by scrolling down or up. This happens in Android and iOS.

I've definitely narrowed it down to the address bar's appearance and disappearance, because:

* it only happens on mobile browsers.
* the address bar doesn't disappear while the page is still loading (at least in Opera), and thus the menu doesn't close when I scroll under that condition.
* the menu won't close if I scroll after the address bar has been hidden.

However, I don't know what to do to fix it; the address bar affects the height of the window/page, not the width, so I'm unsure of why the menu toggles when you scroll up/down.
This method is the simplest way for me to make a responsive menu with how things are set up currently.

Here's the relevant part of the code I'm using:

```
    var winwidth = $(window).width();
    $(window).resize(function() {
        var newwinwidth = $(window).width();
        if(winwidth = newwinwidth && newwinwidth <= 768) {
            // if smaller or equal
            $('.menu ul').hide();
        } else {
            // if larger
            $('.menu ul').show();
        }
    }).resize();

```

Here's a live example of a site on which this happens: <http://jessicacantlope.com>

I've already tried a couple debounce methods to see if that would solve the problem (it doesn't; it just delays the action) and also scoured this website. I've included app-capable meta elements and a few other iOS-specific things.

I also looked into solutions that hide the address bar entirely, but they only work under certain conditions and rely on modifying system UI/UX, which is something I don't want to do. I just want to keep it simple.

Any help would be appreciated. I'm more of a designer than a developer, and I love elegant solutions.

EDIT, 2020: Five+ years later, after having implemented a solution that seemed to work for a while and then failed again, I started tinkering and realized that, for the way I had designed my mobile menu and website, and with some of the things I had tried since then, I had been mistakenly targeting the wrong selectors in my code! And I hadn't thought deeply enough about how to apply the first suggestion. It's not elegantly written so I won't post my final code, but I finally got things in working shape. Thanks, everyone!