GreedyNav
GreedyNav copied to clipboard
`check()` doesn't seem to run properly on page load
Initially when the page loads, there can be overlapping navigation items (the A in about is cut off):
However, if I scroll down and then back up, an event must get triggered because the navigation items stop overlapping:
I have only been able to reproduce this issue on mobile.
Humm.. have you managed to find out what is causing this?
I haven't. (I also know very little about front-end development.) My guess was that check()
isn't responding properly when it's called on document ready, but it is triggered when scrolling. I tried a few other document/window listeners but couldn't fix the problem.
Weird.. I would have hope that at least, jQuery would normalize this kinda behavior across different browsers. the codepen example seems to work in the iOS emulator in dev tools.. have you tried it on your device? This would suggest if the lib is broke or your implementation.
I have a similar issue, and since both of us use the same jekyll theme, it seems the issue it's influenced by minimal-mistakes theme My guess is: there could be elements added by the theme that are not computed correctly by the script, I'll try to investigate further, but for some reason I can reproduce only on my phone, in dev tools everything seems to work seamlessy.
Ok after some stress tests, it seems that in the following function
https://github.com/lukejacksonn/GreedyNav/blob/605f64fee61b15fcae162f1353a25ee23ba2dd71/greedynav.js#L19-L23
w
variable could get some smaller value than what is the real width of elements (in my case, 32 pixel less for every element in the menu)
Since the script start at $(document).ready
I'm pretty sure that is caused by some "racing" between jQuery and CSS.
The only reliable fix I could so far is by replacing $(document).ready(
with $(window).on("load",
in
https://github.com/mmistakes/minimal-mistakes/blob/64a34ee5ae8a37e92b2051828627a957639d911e/assets/js/plugins/jquery.greedy-navigation.js#L7 Obviously that change comes with the downside of waiting everything being loaded...
It's far from being a clean fix, but unfortunately I'm not fluent enough in JS 😥 Since minimal-mistakes uses a different version of the file, I doubt the issue belongs here...
I've been looking in to this a bit with the browser debugger and found that the outerWidth()
reported on the navigation items are not always correct. In my case, the reported width on the first nav element is almost the full browser window width some times (but should be around a 100px only), which causes greedy-nav to hide all items in the overflow menu.
I've not been able to capture with the debugger the case in your screenshot that the element overflows, but I would believe it could be the same issue (I do get the same behavior as you on mobile browser with overflow as in the screenshot), that the reported with is not the actual.
Unfortunately the workaround $(window).on("load"
does not make a difference for me.