Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check() doesn't seem to run properly on page load #18

Open
sktollman opened this issue Jan 28, 2019 · 6 comments
Open

check() doesn't seem to run properly on page load #18

sktollman opened this issue Jan 28, 2019 · 6 comments

Comments

@sktollman
Copy link

Initially when the page loads, there can be overlapping navigation items (the A in about is cut off):
img_3804

However, if I scroll down and then back up, an event must get triggered because the navigation items stop overlapping:
img_3805

I have only been able to reproduce this issue on mobile.

@lukejacksonn
Copy link
Owner

Humm.. have you managed to find out what is causing this?

@sktollman
Copy link
Author

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.

@lukejacksonn
Copy link
Owner

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.

@barsa-net
Copy link

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.

@barsa-net
Copy link

barsa-net commented May 20, 2019

Ok after some stress tests, it seems that in the following function

GreedyNav/greedynav.js

Lines 19 to 23 in 605f64f

$vlinks.children().outerWidth(function(i, w) {
totalSpace += w;
numOfItems += 1;
breakWidths.push(totalSpace);
});

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...

@erikw
Copy link

erikw commented Jul 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants